using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using MBLocale;

public partial class Datasheet : System.Web.UI.Page
{
   // Timer timer1;
    string page_id = "";
    string object_id = "";
    string strPagesetRowId = "";
    string strPageId = "";
    string pageset_id = "";
    string owner_id = "";
    string strMenuRowId = "";
    string strErrMessage = "";
    string search = "";
    string menu_name = "";
    string str_OwnerId = "";
    public ArrayList currencyCode_Rate = new ArrayList();
    HtmlForm frmObj;
    DataTable dt_pageCtr = new DataTable();
    HtmlTable HT = new HtmlTable();
    HtmlTableRow tr_assign = new HtmlTableRow();
    HtmlTableCell tc_cell = new HtmlTableCell();
    DataSet dsePageInfo = new DataSet();
    DataTable dtaData = new DataTable();
    DataSet dseInputInfo;
    DataSet dseNewInfo;
    DataRow droPageData;
    DataSet dseTempInputInfo = new DataSet();
    DataSet dseTempNewInfo = new DataSet();
    ArrayList RowIds = new ArrayList();
    string Existing_ids = "";
    int NoOfRows = 0;
    int TotalCount = 0;
    string object_name = "";
    bool Isadd = false;
    bool IsScrh = false;
    bool IsViewAll = false;
    bool Isaddnew = false;
    bool bRead = false;
    bool bCreate = false;
    bool bEdit = false;
    bool bDelete = false;
    Hashtable sysVar = new Hashtable();
    protected void Page_PreInit(object sender, EventArgs e)
    {
        this.Theme = Session["Theme"].ToString();
        this.Title = "MaxBlox";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["action"] != null && Request.QueryString["action"].ToString() == "InsertNewRecord")
        {
            Response.Write(InsertNewRecord());
            Response.End();
        }

        HDDatabase HDD = new HDDatabase();
        security hdds = new security();
        DynamicDisplayI DDI = new DynamicDisplayI();
        frmObj = (HtmlForm)this.Master.FindControl("Form1");
        if (!IsPostBack)
        {
            table1.Rows.Clear();
        }
        ddlPageViewType.SelectedValue = "DS";
        //timer1 = new Timer();
        if (Session["userid"] == null) Response.Redirect(hdds.SessionExpiryURL);
        if (Session["userid"].ToString() == "") Response.Redirect(hdds.SessionExpiryURL);
        //Datasheet V1.0
        if (HttpContext.Current.Request.QueryString["mn"] != null)
            if (HttpContext.Current.Request.QueryString["mn"].ToString() != "")
                hdds.logMenuClick(Request.QueryString["mn"].ToString());
        if (Request.QueryString["pgs_id"] != null)
        {
            strPagesetRowId = Request.QueryString["pgs_id"].ToString();
            hihpagesetid.Value = Request.QueryString["pgs_id"].ToString();
            //pageset_id = HDD.GetColumnValue("select af_row_id from sy_pgs where pageset_id='" + strPagesetRowId + "'");
            strPageId = HDD.GetColumnValue("select page_id from sy_pgs_mem where pageset_id='" + strPagesetRowId + "'");
            page_id = HDD.GetColumnValue(" select af_row_id from sy_pg where page_id='" + strPageId + "'");
            object_id = HDD.GetColumnValue("select page_table_name from sy_pg where af_row_id='" + page_id + "'");
            owner_id = Session["user_afrowid"].ToString();
            strMenuRowId = HDD.GetColumnValue("select af_row_id from sy_mnu where pageset_id='" + strPagesetRowId + "'");
            //menu_name = HDD.GetColumnValue("select menu_name from sy_mnu where af_row_id='" + strMenuRowId + "'");
            object_name = HDD.GetColumnValue("select object_id from sy_pg where af_row_id='" + page_id + "'");
            //if (strMenuRowId != "")
            //{
            //    string straccord = "";
            //    app_frame ap = new app_frame();
            //    ap.load_menuname(strMenuRowId, ref straccord);
            //    //Datasheet V1.0
            //    Label lbl = (Label)this.Master.FindControl("ltaccordian");
            //    lbl.Text = straccord;
            //}
        }
            
        BusinessUnit.Access ACS = new BusinessUnit.Access(HttpContext.Current.Session["userid"].ToString(), HDD.GetConnection().ConnectionString, strPageId);
        str_OwnerId = ACS.AccessableOwners;
        if (Session["userid"].ToString() == "afadmin")
            if (str_OwnerId == "")
                str_OwnerId = " and 1=1";
        //lblHeader.Text = menu_name;
        hdds.getPagesetRights(strPagesetRowId, ref bRead, ref bCreate, ref bEdit, ref bDelete);
        //HoodTech For Object Rights
        if (!bCreate)
            btnAddNewTop.Visible = false;

        dt_pageCtr = HDD.GetDataTable("select * from sy_pg_ctr where page_id='" + page_id + "'");
        //NoOfRows = GlobalValues.intNoOfRecordsPerPage * Convert.ToInt16(ViewState["MoreCount"].ToString());
        refreshSysVarSectionNames(ref dt_pageCtr);
        refreshSectionnames(ref dt_pageCtr);
        dt_pageCtr.Columns.Add(new DataColumn("attrib_size"));
        DataTable dtAttrib_Size = HDD.GetDataTable("select attrib_id, attrib_size, attrib_data_type from sy_obj_att obj_att inner join sy_obj obj on obj.af_row_id=obj_att.object_id where obj.object_id='" + object_id + "'");
        foreach (DataRow dr in dt_pageCtr.Select("page_id='" + page_id + "'"))
        {
            DataRow[] drr = dtAttrib_Size.Select("attrib_id = '" + dr["control_attrib_id"].ToString() + "'");
            if (drr.Length > 0)
            {
                if (drr[0]["attrib_data_type"].ToString() == "TX")
                    dr["attrib_size"] = drr[0]["attrib_size"].ToString();
            }
        }
        if (bRead)
            LoadControl();
        if (Request.QueryString["try"] != null)
        {
            if (Request.QueryString["ps_id"] != null)
            {
                strPagesetRowId = Request.QueryString["ps_id"].ToString();
                //pageset_id = HDD.GetColumnValue("select af_row_id from sy_pgs where pageset_id='" + strPagesetRowId + "'");
                strPageId = HDD.GetColumnValue("select page_id from sy_pgs_mem where pageset_id='" + strPagesetRowId + "'");
                page_id = HDD.GetColumnValue(" select af_row_id from sy_pg where page_id='" + strPageId + "'");
                object_id = HDD.GetColumnValue("select page_table_name from sy_pg where af_row_id='" + page_id + "'");
                owner_id = Session["user_afrowid"].ToString();
                strMenuRowId = HDD.GetColumnValue("select af_row_id from sy_mnu where pageset_id='" + strPagesetRowId + "'");
                object_name = HDD.GetColumnValue("select object_id from sy_pg where af_row_id='" + page_id + "'");
            }
            if (Request.QueryString["updateMode"] != null)
            {
                hihUpdate.Value = Request.QueryString["updateMode"].ToString();
                GetUpdateData(ref lblMessage);
            }
        }
        
        string strPageSetHeading = CommonFunctions.GetColValueFromPageInfo(strPagesetRowId, "sy_pgs", "pageset_name", "af_row_id='" + strPagesetRowId.Replace("'", "''") + "'");
        if (strPageSetHeading == "")
            strPageSetHeading = hdds.hddb.GetColumnValue("sy_pgs", "pageset_name", "af_row_id='" + strPagesetRowId.Replace("'", "''") + "'");

        lblHeader.Text = "&nbsp;" + GetPageIcons(strPagesetRowId).Text + "&nbsp;<span style='vertical-align:bottom;'>" + strPageSetHeading + "</span>&nbsp;";
        PlaceHolder ph_page_caption = (PlaceHolder)DDI.FindControl(frmObj.Controls, "ph_page_caption");
        ph_page_caption.Controls.Add(lblHeader);

        DataTable dtaPage = CommonFunctions.GetTableFromPageInfo(strPagesetRowId, "sy_pg");
        hdds.displayHelp(dtaPage, DDI.FindControl(frmObj.Controls, "imgHelp"));
        GetPageViewType();
        if (bRead)
        {
            if (!IsPostBack)
            {
                if (frmObj != null) //if (this.FindControl("Form1") != null)
                {
                    loadAllVariables();
                    //frmObj = (HtmlForm)this.Master.FindControl("Form1");//frmObj = (HtmlForm)this.FindControl("Form1")
                    PageInfoLoad PIL = new PageInfoLoad();
                    dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowId);
                }
                NoOfRows = GlobalValues.intNoOfRecordsPerPage;
                ViewState["MoreCount"] = hihMoreCount.Value;
                IsViewAll = true;
                DataLoad();
                //GetPageViewType();
                //getpageicons();
            }
        }
        else
            displayMessage(wrapItAsMessage("You do not have sufficient access permission.", true), "");

    }
    //protected void timer1_Tick(object sender, EventArgs e)
    //{
    //    lblMessage.Text = "";
    //    if (bRead != false)
    //    DataLoad();
    //}
    private void loadAllVariables()
    {
        security hdds = new security();
        Hashtable hsAppVar = new Hashtable();
        Master MA = new Master();
        hdds.loadAppVariables(ref hsAppVar);
        sysVar = new Hashtable();
        if (dsePageInfo.Tables.Count > 0)
            loadPageVariables(dsePageInfo);
        MA.loadSystemVariables(ref sysVar);
        Session["SysVar"] = sysVar;
    }
    private void loadPageVariables(DataSet dsInp)
    {
        try
        {
            string tableName = ""; string pageId = "";
            DataTable dt = dsInp.Tables["Page"];
            foreach (DataRow dr in dt.Rows)
            {
                tableName = dr["page_table_name"].ToString();
                pageId = dr["page_id"].ToString();
                DataRow[] drs = dsInp.Tables["PageCtrl"].Select("page_id='" + dr["af_row_id"].ToString() + "'");//DataRow[] drs = dsInp.Tables["PageCtrl"].Select("page_id='" + dr["page_id"].ToString() + "'");
                for (int i = 0; i < drs.Length; i++)
                    getControlValue(tableName, drs[i]["control_id"].ToString(), pageId);
            }
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in loadPageVariables function: " + e.Message);
        }
    }
    private void getControlValue(string tableName, string controlName, string pageId)
    {
        Control cInp;
        DynamicDisplayI di = new DynamicDisplayI();
        cInp = di.FindControl(this.Controls, pageId + "_" + controlName);
        di = null;
        tableName = tableName + "." + controlName;
        if (cInp != null)
        {
            switch (cInp.GetType().ToString())
            {
                case "System.Web.UI.WebControls.TextBox":
                    TextBox tb = (TextBox)cInp;
                    sysVar.Add(tableName, tb.Text);
                    break;
                case "System.Web.UI.WebControls.DropDownList":
                    DropDownList db = (DropDownList)cInp;
                    sysVar.Add(tableName, db.SelectedValue);
                    break;
                case "System.Web.UI.WebControls.CheckBox":
                    CheckBox cb = (CheckBox)cInp;
                    sysVar.Add(tableName, cb.Checked);
                    break;
                case "System.Web.UI.WebControls.CheckBoxList":
                    CheckBoxList cbl = (CheckBoxList)cInp;
                    //sysVar.Add(tableName, tb.se);
                    break;
                case "System.Web.UI.WebControls.RadioButton":
                    RadioButton rb = (RadioButton)cInp;
                    sysVar.Add(tableName, rb.Checked);
                    break;
                case "System.Web.UI.WebControls.RadioButtonList":
                    RadioButtonList rbl = (RadioButtonList)cInp;
                    //hInp.Add(tableName, tb.Text);
                    break;
                case "System.Web.UI.WebControls.HiddenField":
                    HiddenField hf = (HiddenField)cInp;
                    sysVar.Add(tableName, hf.Value);
                    break;
            }
        }
    }
    private string wrapItAsMessage(string msg, bool isError)
    {
        return "<div class=\"" + (isError == true ? "mbErrorMessage" : "mbMessage") + "\">" + msg + "</div>";
    }
    private void displayMessage(string sMessage, string key) //Changed By Dhanapal
    {
        //Label lblMessage1 = new Label();
        lblMessage.Text = sMessage;
        lblMessage.ForeColor = System.Drawing.Color.Red;
        if (key == "TV")
        {

        }
        else if (key == "CV")
        {

        }
        else
        {
            // tdDisplayGrid.Controls.Add(lblMessage1);
        }
    }

    private void addHeader()
    {
        DataRow[] dr_ctrl = dt_pageCtr.Select("section_name ='__MB_EMPTY_SECTION' AND control_visible=1", "control_seq asc");
        HtmlTableRow Header = new HtmlTableRow();
        //Header.Attributes.Add("Class", "Dynamic_PageHeaderRow");
        Header.Attributes.Add("Class", "Grid_Header");
        if (bDelete != false)
        {
            HtmlTableCell tc_addRemove = new HtmlTableCell();
            //tc_addRemove.InnerHtml = "Delete";
            tc_addRemove.VAlign = "center";
            Header.Cells.Add(tc_addRemove);
        }
        LoadEditPage LEP = new LoadEditPage();
        string Mas_Key = LEP.getMasterDetailKey(object_id);
        foreach (DataRow dr in dr_ctrl)
        {
            HtmlTableCell tc = new HtmlTableCell();
            if (dr["control_name"].ToString().ToLower() != "af_row_id" && dr["control_name"].ToString().ToLower() != Mas_Key.ToLower())
                tc.InnerHtml = dr["control_name"].ToString();
            //string datatype = dr["control_attrib_type"].ToString().ToLower();
            //if (datatype != "tx" && datatype != "da" && datatype != "dt" && datatype != "bo")
            //    tc.Align = "right";
            //else
            //    tc.Align = "left";
            //tc.VAlign = "middle";
            //if (dr["control_name"].ToString().ToLower() == "&nbsp;")
            //    tc.Width = "25px";
            tc.NoWrap = true;
            tc.Attributes.Add("class", "Grid_Header_Cell");
            Header.Cells.Add(tc);
        }
        datasheet.Rows.Add(Header);
    }
    private void refreshSectionnames(ref DataTable dt)
    {
        foreach (DataRow dr in dt.Rows)
        {
            //if (dr["section_name"] == null || dr["section_name"].ToString().Trim() == "")
            //{
                dr["section_name"] = "__MB_EMPTY_SECTION";
            //}
        }
    }
    private void refreshSysVarSectionNames(ref DataTable dt)
    {
        foreach (DataRow dr in dt.Rows)
        {
            switch (dr["control_id"].ToString())
            {
                case "created_by":
                    dr["section_name"] = "__SYS_VAR__";
                    break;
                case "modified_at":
                    dr["section_name"] = "__SYS_VAR__";
                    break;
                case "created_at":
                    dr["section_name"] = "__SYS_VAR__";
                    break;
                case "modified_by":
                    dr["section_name"] = "__SYS_VAR__";
                    break;
                case "owner_id":
                    dr["section_name"] = "__SYS_VAR__";
                    break;
            }
        }
    }
    private void DataLoad()
    {
        HDDatabase HDD = new HDDatabase();
        DynamicDisplayI DDI = new DynamicDisplayI();
        PageInfoLoad PIL = new PageInfoLoad();
        GenerateGrid objGD = new GenerateGrid();
        LoadEditPage LEP = new LoadEditPage();
        Localization li = new Localization();
        try
        {
            Control con;
            string strCtrlId = "";
            string strBindRowID = "";
            string strActualCtrlId = "";
            string strCtrlWidth = "";
            string sAttrib_Size = "";
            string sInputFormatMask = "";
            string strDefaultVal = "";
            string CurrenyValue = "";
            int intPageSeq = 0;
            string sToolTip = "";
            ViewState["RowIds"] = "";
            RowIds.Clear();
            dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowId);
            DataTable dtaPageSet = dsePageInfo.Tables["PageSet"];
            DataTable dtaPage = dsePageInfo.Tables["Page"];
            DataTable dtaPageKeys = dsePageInfo.Tables["PageKeys"];
            DataTable dtaPageCtrl = dsePageInfo.Tables["PageCtrl"];
            DataRow droPage = dtaPage.Rows[intPageSeq];

            DataRow[] dr_ctrl = dt_pageCtr.Select("section_name ='__MB_EMPTY_SECTION' AND control_visible=1", "control_seq asc");

            string sSql = "select attrib_id,attrib_name,is_key,is_primary,object_tooltip from sy_obj_att obj_att inner join sy_obj obj on obj.af_row_id=obj_att.object_id where obj.object_id='" + droPage["object_id"].ToString().Replace("'", "''") + "'";
            Hashtable Tooltips = new Hashtable();
            DataTable dtObjatt = new DataTable();
            dtObjatt = HDD.GetDataTable(sSql);
            foreach (DataRow dr in dtObjatt.Rows)
                Tooltips.Add(dr["attrib_id"].ToString(), dr["object_tooltip"].ToString());
            NoOfRows = GlobalValues.intNoOfRecordsPerPage * Convert.ToInt16(ViewState["MoreCount"].ToString());

            DataTable dt_count = HDD.GetDataTable("select * from " + object_id + " where " + str_OwnerId.Remove(0, 5) + " or owner_id is null ");
            if (dt_count != null)
            {
                TotalCount = dt_count.Rows.Count;
                //Datasheet V1.0
                ViewState["TotalRecords"] = dt_count.Rows.Count;
            }
            string SQL = "select TOP " + NoOfRows + " * from " + object_id + " where " + str_OwnerId.Remove(0, 5) + " or owner_id is null ";
            if (search != "" && IsScrh == true)
                SQL += search;
            SQL += " order by modified_at desc,af_row_id asc";
            DataTable dt_bindData = HDD.GetDataTable(SQL);
            datasheet.Rows.Clear();
            addHeader();
            hihRowCount.Value = Convert.ToString(dt_bindData.Rows.Count - 1);
            string sUTC_Offset = DDI.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id");
            if (dt_bindData.Rows.Count > 0)
            {
                for (int i = 0; i < dt_bindData.Rows.Count; i++)
                {
                    string af_row_id = dt_bindData.Rows[i]["af_row_id"].ToString();
                    Existing_ids += af_row_id + ",";
                    tr_assign = new HtmlTableRow();
                    tr_assign.ID = "tr_assign_" + af_row_id;
                    PageCommonFunctions PCF = new PageCommonFunctions();
                    RowIds.Add(af_row_id);
                    if (bDelete != false)
                    {
                        HtmlTableCell tc_assign = new HtmlTableCell();
                        HtmlAnchor a = new HtmlAnchor();
                        //Datasheet V1.0
                        a.Title = "Delete";
                        a.ID = "btn_remove" + af_row_id.ToString();
                        a.Attributes.Add("onclick", @"javascript:if(confirm(""Are you sure you want to delete '" + objGD.includeJavascriptEscapes(dt_bindData.Rows[i][dr_ctrl[0]["control_id"].ToString()].ToString()) + @"' ?"")){Delete('" + tr_assign.ID.ToString() + "');}else{return false;};");
                        a.ServerClick += new EventHandler(a_ServerClick);
                        a.HRef = "#";
                        HtmlImage img = new HtmlImage();
                        img.ID = "img" + af_row_id.ToString();
                        img.Src = "Images/delete.GIF";
                        img.Border = 0;
                        a.Controls.Add(img);
                        tc_assign.Controls.Add(a);
                        //tc_assign.Width = "2%";
                        tc_assign.Align = "center";
                        tr_assign.Cells.Add(tc_assign);
                        //tc_assign.BgColor = "#ffffff";
                        tc_assign.Attributes.Add("Class", "datasheet_textbox");
                        //tc_assign.Attributes.Add("className", "datasheet_textbox");
                        HiddenField hfobj = new HiddenField();
                        hfobj.ID = "hf_IsNewRow_" + af_row_id;
                        hfobj.Value = "false";
                        tc_assign.Controls.Add(hfobj);
                    }
                    datasheet.Rows.Add(tr_assign);
                    BindControl BC = new BindControl();
                    foreach (DataRow dr in dr_ctrl)
                    {
                        string strAttrib_Type = dr["control_attrib_type"].ToString();
                        strActualCtrlId = dr["control_attrib_id"].ToString();
                        strCtrlId = dr["control_attrib_id"].ToString();
                        string strcontrolHtml = dr["control_html"].ToString();
                        strBindRowID = dr["control_bind_id"].ToString();
                        strCtrlWidth = dr["control_width"].ToString();
                        sAttrib_Size = dr["attrib_size"].ToString();
                        if (dr.Table.Columns.Contains("input_mask_format"))
                            sInputFormatMask = dr["input_mask_format"].ToString();
                        strCtrlId = strCtrlId + "_" + af_row_id.ToString();
                        strDefaultVal = dr["default_value"].ToString();
                        bool IsEdit = Convert.ToBoolean(dr["read_only"].ToString());
                        if (strDefaultVal.StartsWith("{!") && strDefaultVal.EndsWith("}"))
                        {
                            Hashtable hsSysVar = (Hashtable)HttpContext.Current.Session["SysVar"];
                            if (hsSysVar.Contains(strDefaultVal))
                                strDefaultVal = hsSysVar[strDefaultVal].ToString();
                        }
                        else if (strDefaultVal.StartsWith("{@") && strDefaultVal.EndsWith("}"))
                        {
                            security hds = new security();
                            Hashtable hsAppVar = new Hashtable();
                            hds.loadAppVariables(ref hsAppVar);
                            hds = null;
                            if (hsAppVar.Contains(strDefaultVal))
                                strDefaultVal = hsAppVar[strDefaultVal].ToString();
                        }
                        else if (strDefaultVal == "CurrentDate()")
                        {
                            strDefaultVal = DateTime.Now.ToShortDateString();
                        }
                        string Object_af_row_id = HDD.GetColumnValue("select af_row_id from sy_obj where object_id='" + object_name + "'");
                        string IsPrimary = "";
                        switch (strcontrolHtml.ToUpper())
                        {
                            case "TB":
                            case "EM":
                                #region Imran New Lines
                                //tc_cell = new HtmlTableCell();
                                //tc_cell.VAlign = "top";
                                //tc_cell.Attributes.Add("Class", "Dynamic_HtmlTableCell");
                                //TextBox txtObj = new TextBox();
                                //txtObj.ID = "TB_" + strCtrlId;
                                //sToolTip = DDI.getValueFromKey(Tooltips, strActualCtrlId);
                                //if (sToolTip != "")
                                //    txtObj.ToolTip = sToolTip;
                                //if (strCtrlWidth != "")
                                //    txtObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                                //if (strActualCtrlId == GlobalValues.CreatedDate)
                                //{
                                //    txtObj.Text = DateTime.Now.ToString();
                                //    txtObj.Enabled = false;
                                //}
                                //else if (strActualCtrlId == GlobalValues.ModifiedDate)
                                //    txtObj.Enabled = false;
                                //if (sAttrib_Size != "")
                                //    txtObj.MaxLength = Convert.ToInt32(sAttrib_Size);
                                ////if (blnSeqControl)
                                ////    txtObj.Text = intCurrentRow.ToString();
                                //if (!IsEdit) txtObj.Enabled = false;
                                //security sec = new security();
                                //bool change_owner = sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner");
                                //if (strActualCtrlId.ToLower() == "owner_id" && !change_owner)
                                //    txtObj.Enabled = false;
                                //txtObj.CssClass = "controlFont controlWidth datasheet_textbox";
                                //con = (Control)txtObj;
                                //SetValueForCtrl(i, dt_bindData, strcontrolHtml, strActualCtrlId, ref con);
                                //tc_cell.Controls.Add(txtObj);
                                //if (strActualCtrlId == "af_row_id")
                                //{
                                //    txtObj.Visible = false;
                                //    tc_cell.Visible = false;
                                //}
                                //if (strBindRowID != "")
                                //{
                                //    HiddenField hf = new HiddenField();
                                //    hf.ID = "HD1_" + strCtrlId;
                                //    PCF.SetDefaultValueForOwnerID(ref txtObj, ref hf, strActualCtrlId);
                                //    tc_cell.Controls.Add(hf);
                                //}

                                //if (strAttrib_Type == "DT")
                                //{
                                //    PCF.addAjaxCalendarDateTime(txtObj.ID, ref tc_cell);
                                //    txtObj.Text = DDI.getUsersDT(txtObj.Text, sUTC_Offset);
                                //}
                                //if (strAttrib_Type == "DC" || strAttrib_Type == "NU" || strAttrib_Type == "AN" || strAttrib_Type == "FL" || strAttrib_Type == "CU")
                                //    txtObj.Style.Add("text-align", "right");
                                
                                //if (strAttrib_Type == "DA")
                                //{
                                //    tc_cell.Controls.Add(PCF.addAjaxCalendarDate(txtObj.ID));
                                //    if (txtObj.Text != "")
                                //    {
                                //        DateTime da = DateTime.Parse(txtObj.Text);
                                //        txtObj.Text = da.ToString(MBLocalization.getDateFormat(HttpContext.Current.Session["userlocale"].ToString())); // Added by 'Imran Gani' on 19-Mar-2014, for MBLocale
                                //    }
                                //}
                                //if (strBindRowID != "")//sanal
                                //{
                                //    if (strActualCtrlId.ToLower() == "owner_id" && change_owner)
                                //        PCF.AddSearchLink(ref tc_cell, strActualCtrlId, strCtrlId, txtObj.ID, strBindRowID);
                                //    else
                                //        PCF.AddSearchLink(ref tc_cell, strActualCtrlId, strCtrlId, txtObj.ID, strBindRowID);
                                //    //if (strActualCtrlId != "owner_id")
                                //    //    tc_cell.Controls.Add(getBindNewLink(strBindRowID, null));
                                //    tc_cell.Style.Add("white-space", "nowrap");
                                //}
                                //IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                //if (IsPrimary.ToLower() == "true")
                                //    PCF.addMandatoryValidator(ref tc_cell, txtObj);
                                //if (sInputFormatMask != "") 
                                //    PCF.processInputMask(ref tc_cell, txtObj, sInputFormatMask);
                                //if (strcontrolHtml.ToUpper() == "EM")
                                //    PCF.provideEmailValidation(ref tc_cell, txtObj);
                                //string Mas_key = LEP.getMasterDetailKey(object_id);
                                //if (Mas_key != "" & strActualCtrlId == Mas_key)
                                //{
                                //    txtObj.Visible = false;
                                //    tc_cell.Visible = false;
                                //}
                                #endregion
                                
                                tc_cell = new HtmlTableCell();
                                TextBox txt_obj = new TextBox();
                                //tc_cell.BgColor = "#ffffff";
                                //txt_obj.Style.Add("height", "40px");
                                txt_obj.ID = "TB_" + strCtrlId;
                                tc_cell.NoWrap = true;
                                sToolTip = DDI.getValueFromKey(Tooltips, strActualCtrlId);
                                if (sToolTip != "")
                                    txt_obj.ToolTip = sToolTip;
                                
                                if (!bEdit)
                                    txt_obj.ReadOnly = true;
                                    // tc_cell.Disabled = true;
                                //Hoodtech Blocks the master key in the child onbject
                                string Mas_key = LEP.getMasterDetailKey(object_id);
                                if (Mas_key != "" & strActualCtrlId == Mas_key)
                                {
                                    txt_obj.Visible = false;
                                    tc_cell.Visible = false;
                                }
                                if (strCtrlWidth != "")
                                    txt_obj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                                
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                txt_obj.CssClass = "datasheet_textbox";
                                con = (Control)txt_obj;
                                SetValueForCtrl(i, dt_bindData, strcontrolHtml, strActualCtrlId, ref con);
                                tc_cell.Controls.Add(txt_obj);
                                if (strActualCtrlId == "af_row_id")
                                {
                                    txt_obj.Visible = false;
                                    tc_cell.Visible = false;
                                }
                                if (strBindRowID != "")
                                {
                                    HiddenField hf1 = new HiddenField();
                                    hf1.ID = "HD1_" + strCtrlId;
                                    security sec = new security();
                                    //bool change_owner = false;
                                    //if (strActualCtrlId.ToLower() == "owner_id")
                                    //{
                                    //    change_owner = sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner");
                                    //}
                                    //sec = null;
                                    if (strActualCtrlId.ToLower() == "owner_id" && !sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner"))
                                    {
                                        //if (!change_owner)
                                        //{
                                            txt_obj.ReadOnly = true;
                                        //}
                                        //else
                                        //{
                                        //    if (IsEdit == false & bEdit != false)
                                        //        PCF.AddSearchLink(ref tc_cell, strActualCtrlId, hf1.ID, txt_obj.ID, strBindRowID); // added by srivatsan on july 15 2009}
                                        //    tc_cell.Controls.Add(hf1);
                                        //    if (IsEdit == false & bEdit != false)
                                        //        txt_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + txt_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                        //}
                                    }
                                    else
                                    {
                                        tc_cell.Controls.Add(hf1);
                                        if (!IsEdit && bEdit)
                                        {
                                            PCF.AddSearchLink(ref tc_cell, strActualCtrlId, hf1.ID, txt_obj.ID, strBindRowID); // added by srivatsan on july 15 2009}
                                            txt_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + txt_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                            txt_obj.Style.Add("vertical-align", "middle");
                                        }
                                    }
                                    hf1.Value = txt_obj.Text;
                                    HDDatabase Hdd = new HDDatabase();
                                    //BindControl BC = new BindControl();
                                    string strbindtext = "";
                                    string sql1 = BC.GetBindSql(strBindRowID, false);
                                    DataSet ds = new DataSet();
                                    ds = Hdd.GetDataset(sql1);
                                    if (ds != null)
                                    {
                                        if (ds.Tables.Count > 0)
                                        {
                                            if (ds.Tables[0].Rows.Count > 0)
                                            {
                                                DataRow[] drr = ds.Tables[0].Select("val='" + txt_obj.Text + "'");
                                                if (drr.Length > 0)
                                                    strbindtext = drr[0]["fld"].ToString();
                                                else
                                                    strbindtext = "";
                                            }
                                        }
                                    }
                                    txt_obj.Text = strbindtext;
                                }
                                
                                if (IsEdit)
                                    txt_obj.ReadOnly = true;
                                //  txt_obj.v
                                if (strDefaultVal != "")
                                {
                                }
                                if (strActualCtrlId == GlobalValues.CreatedDate)
                                {
                                    txt_obj.Text = DateTime.Now.ToString();
                                    txt_obj.Enabled = false;
                                }
                                else if (strActualCtrlId == GlobalValues.ModifiedDate)
                                {
                                    txt_obj.Enabled = false;
                                }
                                if (sInputFormatMask != "") PCF.processInputMask(ref tc_cell, txt_obj, sInputFormatMask);

                                if (sAttrib_Size != "")
                                    txt_obj.MaxLength = Convert.ToInt32(sAttrib_Size);
                                if (strAttrib_Type == "DT" & bEdit != false & IsEdit == false)
                                {
                                    PageCommonFunctions PC = new PageCommonFunctions();
                                    PC.addAjaxCalendarDateTime(txt_obj.ID, ref tc_cell);
                                    txt_obj.Text = DDI.getUsersDT(txt_obj.Text, sUTC_Offset);
                                }
                                if (strAttrib_Type == "DC" || strAttrib_Type == "NU" || strAttrib_Type == "AN" || strAttrib_Type == "FL" || strAttrib_Type == "CU")
                                    txt_obj.Style.Add("text-align", "right");
                                
                                if (strAttrib_Type == "DA" & bEdit != false & IsEdit == false)
                                {
                                    tc_cell.Controls.Add(PCF.addAjaxCalendarDate(txt_obj.ID));
                                    if (txt_obj.Text != "")
                                    {
                                        DateTime da = DateTime.Parse(txt_obj.Text);
                                        //txt_obj.Text = da.ToString(li.getDateFormat());
                                        txt_obj.Text = da.ToString(MBLocalization.getDateFormat(HttpContext.Current.Session["userlocale"].ToString())); // Added by 'Imran Gani' on 19-Mar-2014, for MBLocale
                                    }
                                }
                                if (strcontrolHtml.ToUpper() == "EM" & bEdit != false & IsEdit == false)
                                    PCF.provideEmailValidation(ref tc_cell, txt_obj, strActualCtrlId, RowIds[i].ToString());
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, txt_obj);
                                loadCurrencySettings();
                                HiddenField HD_Cu = new HiddenField();
                                if (strAttrib_Type.ToLower() == "cu")
                                {
                                    if (txt_obj.Text != "&nbsp;")
                                    {
                                        HD_Cu.ID = "HD_Cu_" + strCtrlId + "_" + RowIds[i].ToString();
                                        HD_Cu.Value = txt_obj.Text;
                                        txt_obj.Text = DDI.manageCurrency(txt_obj.Text, currencyCode_Rate);
                                        tc_cell.Controls.Add(HD_Cu);
                                    }
                                    //txt_obj.Attributes.Add("onfocus", "javascript:GetCurrency('" + CurrenyValue + "','" + txt_obj.ID.ToString() + "');");
                                    txt_obj.Attributes.Add("onfocus", "javascript:GetCurrency('" + HD_Cu.ID.ToString() + "','" + txt_obj.ID.ToString() + "',true);");
                                }
                                if (strBindRowID == "" & strAttrib_Type.ToLower() != "cu")
                                {
                                    if (IsEdit == false & bEdit != false)
                                        txt_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + txt_obj.ID.ToString() + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                }
                                else if (strBindRowID == "" & strAttrib_Type.ToLower() == "cu")
                                    txt_obj.Attributes.Add("onblur", "javascript:GetCurrency('" + HD_Cu.ID.ToString() + "','" + txt_obj.ID.ToString() + "',false);GetData('" + RowIds[i].ToString() + "','" + txt_obj.ID.ToString() + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                txt_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + txt_obj.ID + "','" + (i + 1) + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (tc_cell.Controls.Count <= 1)
                                //if (strBindRowID == "" && IsPrimary.ToLower() != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    txt_obj.Width = Unit.Percentage(90);
                                //}
                                //else if (strBindRowID != "" && IsPrimary.ToLower() == "true")
                                //{
                                //    tc_cell.Width = "170";
                                //    txt_obj.Width = Unit.Percentage(75);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    txt_obj.Width = Unit.Percentage(80);
                                //}
                                #endregion
                                break;
                            case "PW":
                                tc_cell = new HtmlTableCell();
                                TextBox PW_obj = new TextBox();
                                PW_obj.ID = "PW_" + strCtrlId;
                                //PW_obj.Width = Unit.Percentage(100);
                                PW_obj.TextMode = TextBoxMode.Password;
                                //tc_cell.BgColor = "#ffffff";
                                //PW_obj.Style.Add("height", "40px");
                                PW_obj.Attributes.Add("onfocus", "DisableTimer(true);");
                                PW_obj.Attributes.Add("onblur", "DisableTimer(false);");
                                tc_cell.Controls.Add(PW_obj);
                                if (IsEdit)
                                    PW_obj.ReadOnly = true;
                                sToolTip = DDI.getValueFromKey(Tooltips, strActualCtrlId);
                                if (sToolTip != "")
                                    PW_obj.ToolTip = sToolTip;
                                con = (Control)PW_obj;
                                if (!bEdit)
                                    PW_obj.ReadOnly = true;
                                SetValueForCtrl(i, dt_bindData, strcontrolHtml, strActualCtrlId, ref con);
                                PW_obj.CssClass = "datasheet_textbox";
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, PW_obj);
                                PW_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + PW_obj.ID + "','" + (i + 1) + "');");
                                if (IsEdit == false & bEdit != false)
                                    PW_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + PW_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (IsPrimary != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    PW_obj.Width = Unit.Percentage(90);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    PW_obj.Width = Unit.Percentage(90);
                                //}
                                #endregion
                                break;
                            case "ENC": // Added by 'Imran Gani' on 10-Jul-2014, to handle encryption fields.
                                tc_cell = new HtmlTableCell();
                                TextBox ENC_obj = new TextBox();
                                ENC_obj.ID = "ENC_" + strCtrlId;
                                //ENC_obj.Width = Unit.Percentage(100);
                                ENC_obj.Attributes.Add("onfocus", "DisableTimer(true);");
                                ENC_obj.Attributes.Add("onblur", "DisableTimer(false);");
                                tc_cell.Controls.Add(ENC_obj);
                                if (IsEdit)
                                    ENC_obj.ReadOnly = true;
                                sToolTip = DDI.getValueFromKey(Tooltips, strActualCtrlId);
                                if (sToolTip != "")
                                    ENC_obj.ToolTip = sToolTip;
                                con = (Control)ENC_obj;
                                if (!bEdit)
                                    ENC_obj.ReadOnly = true;
                                SetValueForCtrl(i, dt_bindData, strcontrolHtml, strActualCtrlId, ref con);
                                ENC_obj.CssClass = "datasheet_textbox";
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, ENC_obj);
                                ENC_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + ENC_obj.ID + "','" + (i + 1) + "');");
                                if (IsEdit == false & bEdit != false)
                                    ENC_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + ENC_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (IsPrimary != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    ENC_obj.Width = Unit.Percentage(90);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    ENC_obj.Width = Unit.Percentage(90);
                                //}
                                #endregion
                                break;
                            case "AN":
                                tc_cell = new HtmlTableCell();
                                TextBox AN_obj = new TextBox();
                                AN_obj.ID = "AN_" + strCtrlId;
                                //AN_obj.Width = Unit.Percentage(100);
                                //tc_cell.BgColor = "#ffffff";
                                //AN_obj.Style.Add("height", "40px");
                                con = (Control)AN_obj;
                                sToolTip = DDI.getValueFromKey(Tooltips, strActualCtrlId);
                                if (sToolTip != "")
                                    AN_obj.ToolTip = sToolTip;
                                if (bEdit == false)
                                    AN_obj.ReadOnly = true;
                                if (IsEdit == true)
                                    AN_obj.ReadOnly = true;
                                SetValueForCtrl(i, dt_bindData, strcontrolHtml, strActualCtrlId, ref con);
                                if (strCtrlWidth != "")
                                    AN_obj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                                if (sAttrib_Size != "")
                                    AN_obj.MaxLength = Convert.ToInt32(sAttrib_Size);
                                AN_obj.CssClass = "datasheet_textbox";
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, AN_obj);
                                AN_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + AN_obj.ID + "','" + (i + 1) + "');");
                                if (IsEdit == false & bEdit != false)
                                    AN_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + AN_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                tc_cell.Controls.Add(AN_obj);
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (IsPrimary != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    AN_obj.Width = Unit.Percentage(90);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    AN_obj.Width = Unit.Percentage(90);
                                //}
                                #endregion
                                break;
                            case "CB":
                                tc_cell = new HtmlTableCell();
                                CheckBox CB = new CheckBox();
                                //tc_cell.BgColor = "#ffffff";
                                CB.ID = "CB_" + strCtrlId;
                                sToolTip = DDI.getValueFromKey(Tooltips, strActualCtrlId);
                                if (sToolTip != "")
                                    CB.ToolTip = sToolTip;
                                con = (Control)CB;
                                if (bEdit == false)
                                    CB.Enabled = false;
                                if (IsEdit == true)
                                    CB.Enabled = false;
                                SetValueForCtrl(i, dt_bindData, strcontrolHtml, strActualCtrlId, ref con);
                                tc_cell.Controls.Add(CB);
                                if (IsEdit == false & bEdit != false)
                                    CB.Attributes.Add("onclick", "javascript:GetData('" + RowIds[i].ToString() + "','" + CB.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','false');");
                                CB.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + CB.ID + "','" + (i + 1) + "');");
                                tc_cell.Align = "center";
                                break;
                            case "TA":
                                tc_cell = new HtmlTableCell();
                                tc_cell.NoWrap = true;
                                TextBox txtobj = new TextBox();
                                txtobj.TextMode = TextBoxMode.MultiLine;
                                //txtobj.Rows = 4;
                                txtobj.ID = "TA_" + strCtrlId;
                                txtobj.Wrap = true;
                                if (bEdit == false)
                                    txtobj.ReadOnly = true;
                                //DataSheetV3
                                if (IsEdit == true)
                                    txtobj.ReadOnly = true;
                                //txtobj.Width = Unit.Percentage(100);
                                sToolTip = DDI.getValueFromKey(Tooltips, strActualCtrlId);
                                con = (Control)txtobj;
                                SetValueForCtrl(i, dt_bindData, strcontrolHtml, strActualCtrlId, ref con);
                                if (sToolTip != "")
                                    txtobj.ToolTip = sToolTip;
                                txtobj.CssClass = "datasheet_textbox";
                                tc_cell.Controls.Add(txtobj);
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, txtobj);
                                txtobj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + txtobj.ID + "','" + (i + 1) + "');");
                                if (IsEdit == false & bEdit != false)
                                    txtobj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + txtobj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (IsPrimary != "true")
                                //{
                                //    tc_cell.Width = "200px";
                                //    txtobj.Width = Unit.Percentage(95);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "210";
                                //    txtobj.Width = Unit.Percentage(90);
                                //}
                                #endregion
                                break;
                            case "DD":
                                tc_cell = new HtmlTableCell();
                                tc_cell.NoWrap = true;
                                //tc_cell.BgColor = "#ffffff";
                                DropDownList DDL = new DropDownList();
                                //DDL.Width = Unit.Percentage(100);
                                DataTable dt = new DataTable();
                                DDL.ID = "DD_" + strCtrlId;
                                sToolTip = DDI.getValueFromKey(Tooltips, strActualCtrlId);
                                if (bEdit == false)
                                    DDL.Enabled = false;
                                if (sToolTip != "")
                                    DDL.ToolTip = sToolTip;
                                if (strBindRowID != "")
                                {
                                    string sql = "";

                                    sql = BC.GetBindSql(strBindRowID);
                                    if (sql.Trim() != "")
                                        dt = HDD.GetDataTable(sql);
                                    DDL.DataSource = dt;
                                    DDL.DataTextField = "Fld";
                                    DDL.DataValueField = "Val";
                                    DDL.DataBind();
                                }
                                DDL.CssClass = "datasheet_dropdown";
                                con = (DropDownList)DDL;
                                SetValueForCtrl(i, dt_bindData, strcontrolHtml, strActualCtrlId, ref con);
                                tc_cell.Controls.Add(DDL);
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, DDL);
                                DDL.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + DDL.ID + "','" + (i + 1) + "');");
                                if (IsEdit == false & bEdit != false)
                                    DDL.Attributes.Add("onchange", "javascript:GetData('" + RowIds[i].ToString() + "','" + DDL.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (strBindRowID == "" && IsPrimary.ToLower() != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    DDL.Width = Unit.Percentage(90);
                                //}
                                //else if (strBindRowID != "" && IsPrimary.ToLower() == "true")
                                //{
                                //    tc_cell.Width = "170";
                                //    DDL.Width = Unit.Percentage(75);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    DDL.Width = Unit.Percentage(80);
                                //}
                                #endregion
                                break;
                            case "DL": // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                                tc_cell = new HtmlTableCell();
                                tc_cell.NoWrap = true;
                                DropDownList DDL_Droplist = new DropDownList();
                                DDL_Droplist.ID = "DPL_" + strCtrlId;
                                if (bEdit == false)
                                    DDL_Droplist.Enabled = false;
                                if (IsEdit == true)
                                    DDL_Droplist.Enabled = false;
                                sToolTip = DDI.getValueFromKey(Tooltips, strActualCtrlId);
                                if (sToolTip != "")
                                    DDL_Droplist.ToolTip = sToolTip;
                                
                                HDDatabase hd = new HDDatabase();
                                DataTable dt_Droplist = hd.GetDataTable("select * from [sy_pg_ctr_droplist] where [page_id] = '" + dr["page_id"].ToString() + "' and [control_id] = '" + dr["af_row_id"].ToString() + "';");
                                foreach (DataRow dr_temp in dt_Droplist.Select("droplist_value in ('none','empty')"))
                                    dr_temp["droplist_value"] = "";
                                DDL_Droplist.DataSource = dt_Droplist;
                                DDL_Droplist.DataTextField = "droplist_value";
                                DDL_Droplist.DataValueField = "droplist_value";
                                DDL_Droplist.DataBind();
                                #region New code Added by 'Imran Gani' on 19-Mar-2014, to use switch case with MBLocale
                                //foreach (DataRow dr in dt_Droplist.Rows) // Added by 'Imran Gani' on 19-Mar-2014, for MBLocale
                                //{
                                //    string sDLText = dr["droplist_value"].ToString();
                                //    try
                                //    {
                                //        switch (droTemp["control_attrib_type"].ToString().ToLower())
                                //        {
                                //            case "dt":
                                //            case "da":
                                //                sDLText = MBLocalization.getLocalizedDate(HttpContext.Current.Session["userlocale"].ToString(), DateTime.Parse(dr["droplist_value"].ToString()));
                                //                break;
                                //            case "nu":
                                //            case "an":
                                //                sDLText = MBLocalization.getLocalizedInteger(HttpContext.Current.Session["userlocale"].ToString(), int.Parse(dr["droplist_value"].ToString()));
                                //                break;
                                //            case "cu":
                                //            case "dc":
                                //            case "fl":
                                //                sDLText = MBLocalization.getLocalizedDecimal(HttpContext.Current.Session["userlocale"].ToString(), double.Parse(dr["droplist_value"].ToString()));
                                //                break;
                                //        }
                                //    }
                                //    catch (Exception ex)
                                //    {
                                //        sDLText = dr["droplist_value"].ToString();
                                //        dr["droplist_value"] = new Localization().getDBValueFromLocale(dr["droplist_value"].ToString(), droTemp["control_attrib_type"].ToString());
                                //    }
                                //    DDL_Droplist.Items.Add(new ListItem(sDLText, dr["droplist_value"].ToString()));
                                //}
                                #endregion
                                if (HttpContext.Current.Request.QueryString["PK"] == null)
                                    if (strDefaultVal != "")
                                        DDL_Droplist.Items.FindByText(strDefaultVal).Selected = true;

                                DDL_Droplist.CssClass = "datasheet_dropdown";
                                con = (DropDownList)DDL_Droplist;
                                SetValueForCtrl(i, dt_bindData, strcontrolHtml, strActualCtrlId, ref con);
                                tc_cell.Controls.Add(DDL_Droplist);
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, DDL_Droplist);
                                DDL_Droplist.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + DDL_Droplist.ID + "','" + (i + 1) + "');");
                                if (IsEdit == false & bEdit != false)
                                    DDL_Droplist.Attributes.Add("onchange", "javascript:GetData('" + RowIds[i].ToString() + "','" + DDL_Droplist.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (strBindRowID == "" && IsPrimary.ToLower() != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    DDL.Width = Unit.Percentage(90);
                                //}
                                //else if (strBindRowID != "" && IsPrimary.ToLower() == "true")
                                //{
                                //    tc_cell.Width = "170";
                                //    DDL.Width = Unit.Percentage(75);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    DDL.Width = Unit.Percentage(80);
                                //}
                                #endregion
                                break;
                            case "DA":
                                TextBox txtDAObj = new TextBox();
                                txtDAObj.ID = "DA_" + strCtrlId;
                                if (strCtrlWidth != "")
                                    txtDAObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                                if (strActualCtrlId == GlobalValues.CreatedDate)
                                {
                                    txtDAObj.Text = DateTime.Now.ToString();
                                    txtDAObj.Enabled = false;
                                }
                                else if (strActualCtrlId == GlobalValues.ModifiedDate)
                                    txtDAObj.Enabled = false;
                                txtDAObj.CssClass = "datasheet_textbox";
                                tc_cell.Controls.Add(txtDAObj);
                                PCF.addAjaxCalendarDate(txtDAObj.ID);
                                break;
                            case "DT":
                                TextBox txtDTObj = new TextBox();
                                txtDTObj.ID = "DT_" + strCtrlId;
                                if (strCtrlWidth != "")
                                    txtDTObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                                if (strActualCtrlId == GlobalValues.CreatedDate)
                                {
                                    txtDTObj.Text = DateTime.Now.ToString();
                                    txtDTObj.Enabled = false;
                                }
                                else if (strActualCtrlId == GlobalValues.ModifiedDate)
                                    txtDTObj.Enabled = false;
                                txtDTObj.CssClass = "datasheet_textbox";
                                tc_cell.Controls.Add(txtDTObj);
                                PCF.addAjaxCalendarDateTime(txtDTObj.ID, ref tc_cell);
                                break;
                        }
                        if (tc_cell.Controls.Count > 0)
                            tr_assign.Cells.Add(tc_cell);
                    }
                    int intRow = (datasheet.Rows.Count + 1) % 2;
                    //tr_assign.VAlign = "middle";
                    tr_assign.Attributes.Add("Class", "Grid_Row" + intRow.ToString());
                    tr_assign.Attributes.Add("onMouseOver", "this.className='Grid_Scroll_BG'");
                    tr_assign.Attributes.Add("onMouseOut", "this.className='" + "Grid_Row" + intRow.ToString() + "'");
                    tr_assign.Height = "21px"; // sirvatsan
                }
            }
            else
            {
                Isadd = true;
                if (IsScrh == false)
                {
                    addRow();
                }
                else if (IsScrh == true)
                {
                    HtmlTableRow tr_NoRecords = new HtmlTableRow();
                    tr_NoRecords.Align = "left";
                    HtmlTableCell tc_NoRecords = new HtmlTableCell();
                    Label lbl_NoRecords = new Label();
                    lbl_NoRecords.CssClass = "controlFont";
                    lbl_NoRecords.Text = "No Records Available";
                    tr_NoRecords.Style.Add("class", "controlFont");
                    tc_NoRecords.Controls.Add(lbl_NoRecords);
                    tr_NoRecords.Cells.Add(tc_NoRecords);
                    datasheet.Rows.Add(tr_NoRecords);
                }
            }

            ViewState["RowIds"] = RowIds;
            Existing_ids = Existing_ids.TrimEnd(',');
            hihexistingIds.Value = Existing_ids;
            hihUpdate.Value = "";
            hihrowids.Value = "";
            HtmlTableRow Footer = new HtmlTableRow();
            Footer.Attributes.Add("Class", "displaygridbottom");
            HtmlTableCell tc_more = new HtmlTableCell();
            tc_more.ColSpan = dr_ctrl.Length + 1;
            tc_more.Style.Add("font-family", "Verdana");
            tc_more.Style.Add("font-size", "11px");
            tc_more.Height = "20px";
            tc_more.Controls.Add(new LiteralControl("&nbsp;"));
            LinkButton lnkMore = new LinkButton();
            lnkMore.ID = "lnk_More";
            //lnkMore.CssClass = "controlFont";
            lnkMore.ForeColor = System.Drawing.Color.Blue;
            lnkMore.Text = "More";
            //lnkMore.Font.Name = "Arial";
            //lnkMore.Font.Size = 10;
            lnkMore.Attributes.Add("onclick", "javascript:showSave(true);");
            lnkMore.Click += new EventHandler(lnkMore_Click);
            Label count = new Label();
            count.ID = "lbl_count";
            //count.CssClass = "controlFont";
            if (TotalCount < GlobalValues.intNoOfRecordsPerPage)
                count.Text = " Showing record(s) 1 to " + TotalCount + " of " + TotalCount;
            else if (TotalCount > GlobalValues.intNoOfRecordsPerPage & TotalCount > NoOfRows)
            {
                tc_more.Controls.Add(lnkMore);
                count.Text = " Showing record(s) 1 to " + NoOfRows + " of " + TotalCount;
            }
            else if (TotalCount > GlobalValues.intNoOfRecordsPerPage & TotalCount < NoOfRows)
                count.Text = " Showing record(s) 1 to" + TotalCount + " of " + TotalCount;
            tc_more.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
            tc_more.Controls.Add(count);
            Footer.Cells.Add(tc_more);
            datasheet.Rows.Add(Footer);
            security HDS = new security();
            GenerateGrid objGG = new GenerateGrid();
            if (HDS.allRightsForNGMODEL() == false)
            {
                objGG.showadditionalsections(strPagesetRowId, ref frmObj, dsePageInfo);
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : DataLoad : " + ex.Message);
        }
        finally
        {
            DDI = null;
            PIL = null;
            LEP = null;
        }
    }
    public void loadCurrencySettings()
    {
        ArrayList cols = new ArrayList();
        DynamicDisplayI DDI = new DynamicDisplayI();
        cols.Add("c_rate");
        cols.Add("c_code");
        currencyCode_Rate = DDI.getUserSetting("sy_usr", "currency_id", "sy_currency", cols, "c_code");
        currencyCode_Rate.Add(DDI.getCorporateCurrency());
    }
    private void lnkMore_Click(Object sender, EventArgs e)
    {
        int count = Convert.ToInt16(ViewState["MoreCount"].ToString()) + 1;
        ViewState["MoreCount"] = count;
        DataLoad();
    }
    private void SetValueForCtrl(int CurrentRow, DataTable dt_InputData, string strControlHtml, string strCtrlID, ref Control conobj)
    {
        if (strControlHtml != "")
        {
            switch (strControlHtml.ToUpper())
            {
                case "TB":
                case "EM":
                case "TA":
                    if (conobj is TextBox)
                    {
                        TextBox txtObj = (TextBox)conobj;
                        for (int i = 0; i < dt_InputData.Columns.Count; i++)
                        {
                            if (strCtrlID == dt_InputData.Columns[i].ColumnName)
                            {
                                txtObj.Text = dt_InputData.Rows[CurrentRow][strCtrlID].ToString();
                            }
                        }
                    }
                    break;
                case "PW": // Added by 'Imran Gani' on 10-Jul-2014, to handle encryption fields.
                case "ENC":
                    if (conobj is TextBox)
                    {
                        TextBox txtObj = (TextBox)conobj;
                        for (int i = 0; i < dt_InputData.Columns.Count; i++)
                        {
                            if (strCtrlID == dt_InputData.Columns[i].ColumnName)
                            {
                                txtObj.Text = security.decrypt(dt_InputData.Rows[CurrentRow][strCtrlID].ToString());
                            }
                        }
                    }
                    break;
                case "DD":
                case "DL":
                    if (conobj is DropDownList)
                    {
                        DropDownList DD = (DropDownList)conobj;
                        for (int i = 0; i < dt_InputData.Columns.Count; i++)
                        {
                            if (strCtrlID == dt_InputData.Columns[i].ColumnName)
                            {
                                DD.SelectedValue = dt_InputData.Rows[CurrentRow][strCtrlID].ToString();
                            }
                        }
                    }
                    break;
                case "AN":
                    if (conobj is TextBox)
                    {
                        TextBox TB = (TextBox)conobj;
                        for (int i = 0; i < dt_InputData.Columns.Count; i++)
                        {
                            if (strCtrlID == dt_InputData.Columns[i].ColumnName)
                            {
                                TB.Text = dt_InputData.Rows[CurrentRow][strCtrlID].ToString();
                                TB.ReadOnly = true;
                            }
                        }
                    }
                    break;
                case "CB":
                    if (conobj is CheckBox)
                    {
                        CheckBox CB = (CheckBox)conobj;
                        for (int i = 0; i < dt_InputData.Columns.Count; i++)
                        {
                            if (strCtrlID == dt_InputData.Columns[i].ColumnName)
                            {
                                if (dt_InputData.Rows[CurrentRow][strCtrlID].ToString() != null & dt_InputData.Rows[CurrentRow][strCtrlID].ToString() != "")
                                    CB.Checked = Convert.ToBoolean(dt_InputData.Rows[CurrentRow][strCtrlID].ToString());
                            }
                        }
                    }
                    break;
            }
        }

    }

    private void LoadControl()
    {
        ArrayList RowIds = new ArrayList();
        addHeader();
        HDDatabase HDD = new HDDatabase();
        Localization li = new Localization();
        try
        {
            char[] delimiters = new char[] { ',' };
            if (Request.QueryString["rowid"] != null)
            {
                string[] row = Request.QueryString["rowid"].ToString().Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < row.Length; i++)
                {
                    RowIds.Add(row[i].ToString());
                }
            }
            else
                RowIds = (ArrayList)ViewState["RowIds"];
            DataRow[] dr_ctrl = dt_pageCtr.Select("section_name ='__MB_EMPTY_SECTION'  AND control_visible=1", "control_seq asc");

            //DataTable dt_count = HDD.GetDataTable("select * from " + object_id + " where " + str_OwnerId.Remove(0, 5));
            if (RowIds != null)
                TotalCount = RowIds.Count;
            if (RowIds != null)
            {
                for (int i = 0; i < RowIds.Count; i++)
                {
                    tr_assign = new HtmlTableRow();
                    tr_assign.ID = "tr_assign_" + RowIds[i].ToString();
                    Control con;
                    string strCtrlDesc = "";
                    int intCurrentRow = 0;
                    string strCtrlId = "";
                    string strCtrlColumn = "";
                    string strBindRowID = "";
                    string strActualCtrlId = "";
                    string strCtrlWidth = "";
                    string sAttrib_Size = "";
                    string sInputFormatMask = "";
                    string strDefaultVal = "";
                    string CurrenyValue = "";

                    if (bDelete != false)
                    {
                        HtmlTableCell tc_assign = new HtmlTableCell();
                        HtmlAnchor a = new HtmlAnchor();
                        //Datasheet V1.0
                        a.Title = "Delete";
                        a.ID = "btn_remove" + RowIds[i].ToString();
                        a.Attributes.Add("onclick", "javascript:if(confirm('Are you sure you want to delete ?')){Delete('" + tr_assign.ID.ToString() + "');}else{return false;};");
                        a.ServerClick += new EventHandler(a_ServerClick);
                        a.HRef = "#";
                        HtmlImage img = new HtmlImage();
                        img.ID = "img" + RowIds[i].ToString();
                        img.Src = "Images/delete.GIF";
                        img.Border = 0;
                        a.Controls.Add(img);
                        tc_assign.Controls.Add(a);
                        tc_assign.Align = "center";
                        //tc_assign.Width = "2%";
                        //tc_assign.BgColor = "#ffffff";
                        tr_assign.Cells.Add(tc_assign);
                        tc_assign.Attributes.Add("Class", "datasheet_textbox");
                        tc_assign.Attributes.Add("className", "datasheet_textbox");
                        HiddenField hfobj = new HiddenField();
                        hfobj.ID = "hf_IsNewRow_" + RowIds[i].ToString();
                        hfobj.Value = "false";
                        tc_assign.Controls.Add(hfobj);
                    }
                    datasheet.Rows.Add(tr_assign);
                    foreach (DataRow dr in dr_ctrl)
                    {
                        string strAttrib_Type = dr["control_attrib_type"].ToString();
                        strActualCtrlId = dr["control_attrib_id"].ToString();
                        strCtrlId = dr["control_attrib_id"].ToString();
                        string strcontrolHtml = dr["control_html"].ToString();

                        strBindRowID = dr["control_bind_id"].ToString();
                        strCtrlWidth = dr["control_width"].ToString();
                        sAttrib_Size = dr["attrib_size"].ToString();
                        if (dr.Table.Columns.Contains("input_mask_format"))
                            sInputFormatMask = dr["input_mask_format"].ToString();
                        strCtrlId = strCtrlId + "_" + RowIds[i].ToString();
                        strDefaultVal = dr["default_value"].ToString();
                        bool IsEdit = Convert.ToBoolean(dr["read_only"].ToString());

                        if (strDefaultVal.StartsWith("{!") && strDefaultVal.EndsWith("}"))
                        {
                            //strDefaultVal = strDefaultVal.Substring(2, strDefaultVal.Length - 2 - 1);
                            Hashtable hsSysVar = (Hashtable)HttpContext.Current.Session["SysVar"];
                            if (hsSysVar.Contains(strDefaultVal))
                                strDefaultVal = hsSysVar[strDefaultVal].ToString();
                        }
                        else if (strDefaultVal.StartsWith("{@") && strDefaultVal.EndsWith("}"))
                        {
                            security hds = new security();
                            Hashtable hsAppVar = new Hashtable();
                            hds.loadAppVariables(ref hsAppVar);
                            hds = null;
                            if (hsAppVar.Contains(strDefaultVal))
                                strDefaultVal = hsAppVar[strDefaultVal].ToString();
                        }
                        else if (strDefaultVal == "CurrentDate()")
                        {
                            strDefaultVal = DateTime.Now.ToShortDateString();
                        }
                        string Object_af_row_id = HDD.GetColumnValue("select af_row_id from sy_obj where object_id='" + object_name + "'");
                        PageCommonFunctions PCF = new PageCommonFunctions();
                        ScreenReader SR = new ScreenReader();
                        DynamicDisplayI DDI = new DynamicDisplayI();
                        string sUTC_Offset = DDI.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id");
                        string IsPrimary = "";
                        switch (strcontrolHtml.ToUpper())
                        {
                            case "TB":
                            case "EM":
                                tc_cell = new HtmlTableCell();
                                //tc_cell.BgColor = "#ffffff";
                                TextBox txt_obj = new TextBox();
                                txt_obj.ID = "TB_" + strCtrlId;
                                tc_cell.NoWrap = true;
                                //txt_obj.Style.Add("height", "40px");

                                if (bEdit == false)
                                {
                                    txt_obj.ReadOnly = true;
                                    //txt_obj.Enabled = false;
                                    //  tc_cell.Disabled = true;
                                }
                                HiddenField HD_Cu = new HiddenField();
                                if (strActualCtrlId == "af_row_id")
                                {
                                    txt_obj.Text = RowIds[i].ToString();
                                    txt_obj.Visible = false;
                                    tc_cell.Visible = false;
                                }
                                txt_obj.CssClass = "datasheet_textbox";
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                
                                if (strAttrib_Type.ToLower() == "cu")
                                {
                                    if (txt_obj.Text != "&nbsp;")
                                    {
                                        HD_Cu.ID = "HD_Cu_" + strCtrlId + "_" + RowIds[i].ToString();
                                        HD_Cu.Value = txt_obj.Text;
                                        txt_obj.Text = DDI.manageCurrency(txt_obj.Text, currencyCode_Rate);
                                        tc_cell.Controls.Add(HD_Cu);
                                    }
                                    //txt_obj.Attributes.Add("onfocus", "javascript:GetCurrency('" + CurrenyValue + "','" + txt_obj.ID.ToString() + "');");
                                    txt_obj.Attributes.Add("onfocus", "javascript:GetCurrency('" + HD_Cu.ID.ToString() + "','" + txt_obj.ID.ToString() + "',true);");
                                }
                                if (strBindRowID == "" & strAttrib_Type.ToLower() != "cu")
                                {
                                    if (IsEdit == false & bEdit != false)
                                        txt_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + txt_obj.ID.ToString() + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                }
                                else if (strBindRowID == "" & strAttrib_Type.ToLower() == "cu")
                                    txt_obj.Attributes.Add("onblur", "javascript:GetCurrency('" + HD_Cu.ID.ToString() + "','" + txt_obj.ID.ToString() + "',false);GetData('" + RowIds[i].ToString() + "','" + txt_obj.ID.ToString() + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                //txt_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + txt_obj.ID.ToString() + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "');");
                                tc_cell.Controls.Add(txt_obj);
                                if (IsEdit == true)
                                    txt_obj.Enabled = false;

                                if (strBindRowID != "")
                                {
                                    HiddenField hf1 = new HiddenField();
                                    hf1.ID = "HD1_" + strCtrlId;
                                    security sec = new security();
                                    //bool change_owner = false;
                                    //if (strActualCtrlId.ToLower() == "owner_id")
                                    //{
                                    //    change_owner = sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner");
                                    //}
                                    //sec = null;
                                    if (strActualCtrlId.ToLower() == "owner_id" && !sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner"))
                                    {
                                        //if (!change_owner)
                                        //{
                                            txt_obj.Enabled = false;
                                        //}
                                        //else
                                        //{
                                        //    if (IsEdit == false & bEdit != false)
                                        //        PCF.AddSearchLink(ref tc_cell, strActualCtrlId, hf1.ID, txt_obj.ID, strBindRowID);
                                        //    tc_cell.Controls.Add(hf1);
                                        //    txt_obj.Enabled = true;
                                        //    if (IsEdit == false & bEdit != false)
                                        //        txt_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + txt_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                        //}
                                    }
                                    else
                                    {
                                        tc_cell.Controls.Add(hf1);
                                        if (!IsEdit && bEdit)
                                        {
                                            PCF.AddSearchLink(ref tc_cell, strActualCtrlId, hf1.ID, txt_obj.ID, strBindRowID);
                                            txt_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + txt_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                            txt_obj.Style.Add("vertical-align", "middle");
                                        }
                                    }

                                }
                                if (sInputFormatMask != "") 
                                    PCF.processInputMask(ref tc_cell, txt_obj, sInputFormatMask);
                                
                                if (strAttrib_Type == "DC" || strAttrib_Type == "NU" || strAttrib_Type == "AN" || strAttrib_Type == "FL" || strAttrib_Type == "CU")
                                    txt_obj.Style.Add("text-align", "right");

                                if (strAttrib_Type == "DT" & bEdit != false & IsEdit == false)
                                {
                                    PageCommonFunctions PC = new PageCommonFunctions();
                                    PC.addAjaxCalendarDateTime(txt_obj.ID, ref tc_cell);
                                    txt_obj.Text = DDI.getUsersDT(txt_obj.Text, sUTC_Offset);
                                }
                                if (strAttrib_Type == "DA" & bEdit != false & IsEdit == false)
                                {
                                    tc_cell.Controls.Add(PCF.addAjaxCalendarDate(txt_obj.ID));
                                    if (txt_obj.Text != "")
                                    {
                                        DateTime da = DateTime.Parse(txt_obj.Text);
                                        //txt_obj.Text = da.ToString(li.getDateFormat());
                                        txt_obj.Text = da.ToString(MBLocalization.getDateFormat(HttpContext.Current.Session["userlocale"].ToString())); // Added by 'Imran Gani' on 19-Mar-2014, for MBLocale
                                    }
                                }
                                if (strcontrolHtml.ToUpper() == "EM" & bEdit != false & IsEdit == false)
                                    PCF.provideEmailValidation(ref tc_cell, txt_obj, strActualCtrlId, RowIds[i].ToString());
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, txt_obj);
                                if (strDefaultVal != "")
                                {
                                    txt_obj.Text = strDefaultVal;
                                    //txt_obj.Enabled = false;
                                }
                                txt_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + txt_obj.ID + "','" + (i + 1) + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (tc_cell.Controls.Count <= 1)
                                //if (strBindRowID == "" && IsPrimary.ToLower() != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    txt_obj.Width = Unit.Percentage(90);
                                //}
                                //else if (strBindRowID != "" && IsPrimary.ToLower() == "true")
                                //{
                                //    tc_cell.Width = "170";
                                //    txt_obj.Width = Unit.Percentage(75);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    txt_obj.Width = Unit.Percentage(80);
                                //}
                                #endregion
                                break;
                            case "PW":
                                tc_cell = new HtmlTableCell();
                                //tc_cell.BgColor = "#ffffff";
                                tc_cell.NoWrap = true;
                                TextBox PW_obj = new TextBox();
                                if (bEdit == false)
                                    PW_obj.Enabled = false;
                                if (IsEdit == true)
                                    PW_obj.Enabled = false;
                                //PW_obj.Style.Add("height", "40px");                            
                                PW_obj.ID = "PW_" + strCtrlId;
                                //PW_obj.Width = Unit.Percentage(100);
                                PW_obj.TextMode = TextBoxMode.Password;
                                PW_obj.CssClass = "datasheet_textbox";
                                tc_cell.Controls.Add(PW_obj);
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, PW_obj);
                                if (IsEdit == false & bEdit != false)
                                    PW_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + PW_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                PW_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + PW_obj.ID + "','" + (i + 1) + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (IsPrimary != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    PW_obj.Width = Unit.Percentage(90);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    PW_obj.Width = Unit.Percentage(90);
                                //}
                                #endregion
                                break;
                            case "ENC": // Added by 'Imran Gani' on 10-Jul-2014, to handle encryption fields.
                                tc_cell = new HtmlTableCell();
                                tc_cell.NoWrap = true;
                                TextBox ENC_obj = new TextBox();
                                if (bEdit == false)
                                    ENC_obj.Enabled = false;
                                if (IsEdit == true)
                                    ENC_obj.Enabled = false;
                                ENC_obj.ID = "ENC_" + strCtrlId;
                                //ENC_obj.Width = Unit.Percentage(100);
                                ENC_obj.CssClass = "datasheet_textbox";
                                tc_cell.Controls.Add(ENC_obj);
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, ENC_obj);
                                if (IsEdit == false & bEdit != false)
                                    ENC_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + ENC_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                ENC_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + ENC_obj.ID + "','" + (i + 1) + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (IsPrimary != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    ENC_obj.Width = Unit.Percentage(90);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    ENC_obj.Width = Unit.Percentage(90);
                                //}
                                #endregion
                                break;
                            case "AN":
                                tc_cell = new HtmlTableCell();
                                //tc_cell.BgColor = "#ffffff";
                                tc_cell.NoWrap = true;
                                TextBox AN_obj = new TextBox();
                                if (bEdit == false)
                                    AN_obj.Enabled = false;
                                if (IsEdit == true)
                                    AN_obj.Enabled = false;
                                //AN_obj.Style.Add("height", "40px");
                                //DataSheetV3
                                AN_obj.ID = "AN_" + strCtrlId;
                                tc_cell.Controls.Add(AN_obj);
                                //AN_obj.Width = Unit.Percentage(100);
                                AN_obj.CssClass = "datasheet_textbox";
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, AN_obj);
                                if (IsEdit == false & bEdit != false)
                                    AN_obj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + AN_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                AN_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + AN_obj.ID + "','" + (i + 1) + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (IsPrimary != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    AN_obj.Width = Unit.Percentage(90);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    AN_obj.Width = Unit.Percentage(90);
                                //}
                                #endregion
                                break;
                            case "CB":
                                tc_cell = new HtmlTableCell();
                                //tc_cell.BgColor = "#ffffff";
                                CheckBox CB = new CheckBox();
                                if (bEdit == false)
                                    CB.Enabled = false;
                                if (IsEdit == true)
                                    CB.Enabled = false;

                                CB.ID = "CB_" + strCtrlId;
                                string cb_checked = "";
                                if (CB.Checked == true)
                                    cb_checked = " true";
                                else
                                    cb_checked = "false";
                                CB.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + CB.ID + "','" + (i + 1) + "');");
                                if (IsEdit == false & bEdit != false)
                                    CB.Attributes.Add("onclick", "javascript:GetData('" + RowIds[i].ToString() + "','" + CB.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','false');");
                                tc_cell.Controls.Add(CB);
                                tc_cell.Align = "center";
                                break;
                            case "TA":
                                tc_cell = new HtmlTableCell();
                                tc_cell.NoWrap = true;
                                TextBox txtobj = new TextBox();
                                txtobj.TextMode = TextBoxMode.MultiLine;
                                //txtobj.Rows = 4;
                                txtobj.ID = "TA_" + strCtrlId;
                                txtobj.Wrap = true;
                                if (bEdit == false)
                                    txtobj.Enabled = false;
                                if (IsEdit == true)
                                    txtobj.Enabled = false;
                                //txtobj.Width = Unit.Percentage(100);
                                txtobj.CssClass = "datasheet_textbox";
                                tc_cell.Controls.Add(txtobj);
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, txtobj);
                                if (strBindRowID == "")
                                {
                                    if (IsEdit == false & bEdit != false)
                                        txtobj.Attributes.Add("onblur", "javascript:GetData('" + RowIds[i].ToString() + "','" + txtobj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                }
                                txtobj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + txtobj.ID + "','" + (i + 1) + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (IsPrimary != "true")
                                //{
                                //    tc_cell.Width = "200px";
                                //    txtobj.Width = Unit.Percentage(95);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "210";
                                //    txtobj.Width = Unit.Percentage(90);
                                //}
                                #endregion
                                break;
                            case "DD":
                                tc_cell = new HtmlTableCell();
                                tc_cell.NoWrap = true;
                                //  AN_obj.Style.Add("height", "40px");
                                //tc_cell.BgColor = "#ffffff";
                                DropDownList DDL = new DropDownList();
                                BindControl BC = new BindControl();
                                DataTable dt = new DataTable();
                                DDL.ID = "DD_" + strCtrlId;
                                //DDL.Width = Unit.Percentage(100);
                                if (bEdit == false)
                                    DDL.Enabled = false;
                                if (IsEdit == true)
                                    DDL.Enabled = false;
                                if (strBindRowID != "")
                                {
                                    string sql = "";
                                    sql = BC.GetBindSql(strBindRowID);
                                    if (sql.Trim() != "")
                                        dt = HDD.GetDataTable(sql);
                                    DDL.DataSource = dt;
                                    DDL.DataTextField = "Fld";
                                    DDL.DataValueField = "Val";
                                    DDL.DataBind();
                                }
                                DDL.CssClass = "datasheet_dropdown";
                                tc_cell.Controls.Add(DDL);
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, DDL);
                                if (IsEdit == false & bEdit != false)
                                    DDL.Attributes.Add("onchange", "javascript:GetData('" + RowIds[i].ToString() + "','" + DDL.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                DDL.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + DDL.ID + "','" + (i + 1) + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (strBindRowID == "" && IsPrimary.ToLower() != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    DDL.Width = Unit.Percentage(90);
                                //}
                                //else if (strBindRowID != "" && IsPrimary.ToLower() == "true")
                                //{
                                //    tc_cell.Width = "170";
                                //    DDL.Width = Unit.Percentage(75);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    DDL.Width = Unit.Percentage(80);
                                //}
                                #endregion
                                break;
                            case "DL": // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                                tc_cell = new HtmlTableCell();
                                tc_cell.NoWrap = true;
                                DropDownList DDL_Droplist = new DropDownList();
                                DDL_Droplist.ID = "DPL_" + strCtrlId;
                                if (bEdit == false)
                                    DDL_Droplist.Enabled = false;
                                if (IsEdit == true)
                                    DDL_Droplist.Enabled = false;
                                HDDatabase hd = new HDDatabase();
                                DataTable dt_Droplist = hd.GetDataTable("select * from [sy_pg_ctr_droplist] where [page_id] = '" + dr["page_id"].ToString() + "' and [control_id] = '" + dr["af_row_id"].ToString() + "';");
                                foreach (DataRow dr_temp in dt_Droplist.Select("droplist_value in ('none','empty')"))
                                    dr_temp["droplist_value"] = "";
                                DDL_Droplist.DataSource = dt_Droplist;
                                DDL_Droplist.DataTextField = "droplist_value";
                                DDL_Droplist.DataValueField = "droplist_value";
                                DDL_Droplist.DataBind();
                                #region New code Added by 'Imran Gani' on 19-Mar-2014, to use switch case with MBLocale
                                //foreach (DataRow dr in dt_Droplist.Rows) // Added by 'Imran Gani' on 19-Mar-2014, for MBLocale
                                //{
                                //    string sDLText = dr["droplist_value"].ToString();
                                //    try
                                //    {
                                //        switch (droTemp["control_attrib_type"].ToString().ToLower())
                                //        {
                                //            case "dt":
                                //            case "da":
                                //                sDLText = MBLocalization.getLocalizedDate(HttpContext.Current.Session["userlocale"].ToString(), DateTime.Parse(dr["droplist_value"].ToString()));
                                //                break;
                                //            case "nu":
                                //            case "an":
                                //                sDLText = MBLocalization.getLocalizedInteger(HttpContext.Current.Session["userlocale"].ToString(), int.Parse(dr["droplist_value"].ToString()));
                                //                break;
                                //            case "cu":
                                //            case "dc":
                                //            case "fl":
                                //                sDLText = MBLocalization.getLocalizedDecimal(HttpContext.Current.Session["userlocale"].ToString(), double.Parse(dr["droplist_value"].ToString()));
                                //                break;
                                //        }
                                //    }
                                //    catch (Exception ex)
                                //    {
                                //        sDLText = dr["droplist_value"].ToString();
                                //        dr["droplist_value"] = new Localization().getDBValueFromLocale(dr["droplist_value"].ToString(), droTemp["control_attrib_type"].ToString());
                                //    }
                                //    DDL_Droplist.Items.Add(new ListItem(sDLText, dr["droplist_value"].ToString()));
                                //}
                                #endregion
                                if (HttpContext.Current.Request.QueryString["PK"] == null)
                                    if (strDefaultVal != "")
                                        DDL_Droplist.Items.FindByText(strDefaultVal).Selected = true;

                                DDL_Droplist.CssClass = "datasheet_dropdown";
                                tc_cell.Controls.Add(DDL_Droplist);
                                IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                                if (IsPrimary.ToLower() == "true")
                                    PCF.addMandatoryValidator(ref tc_cell, DDL_Droplist);
                                if (IsEdit == false & bEdit != false)
                                    DDL_Droplist.Attributes.Add("onchange", "javascript:GetData('" + RowIds[i].ToString() + "','" + DDL_Droplist.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                DDL_Droplist.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + DDL_Droplist.ID + "','" + (i + 1) + "');");
                                #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                                //if (strBindRowID == "" && IsPrimary.ToLower() != "true")
                                //{
                                //    tc_cell.Width = "140px";
                                //    DDL.Width = Unit.Percentage(90);
                                //}
                                //else if (strBindRowID != "" && IsPrimary.ToLower() == "true")
                                //{
                                //    tc_cell.Width = "170";
                                //    DDL.Width = Unit.Percentage(75);
                                //}
                                //else
                                //{
                                //    tc_cell.Width = "150";
                                //    DDL.Width = Unit.Percentage(80);
                                //}
                                #endregion
                                break;
                        }
                        tr_assign.Cells.Add(tc_cell);
                    }
                    int intRow = (datasheet.Rows.Count + 1) % 2;
                    //tr_assign.VAlign = "middle";
                    tr_assign.Attributes.Add("Class", "Grid_Row" + intRow.ToString());
                    tr_assign.Attributes.Add("onMouseOver", "this.className='Grid_Scroll_BG'");
                    tr_assign.Attributes.Add("onMouseOut", "this.className='" + "Grid_Row" + intRow.ToString() + "'");
                    tr_assign.Height = "21px"; // sirvatsan
                }
            }

            HtmlTableRow Footer = new HtmlTableRow();
            Footer.Attributes.Add("Class", "displaygridbottom");
            HtmlTableCell tc_more = new HtmlTableCell();
            LinkButton lnkMore = new LinkButton();
            tc_more.ColSpan = dr_ctrl.Length + 1;
            tc_more.Style.Add("font-family", "Verdana");
            tc_more.Style.Add("font-size", "11px");
            tc_more.Height = "20px";
            tc_more.Controls.Add(new LiteralControl("&nbsp;"));
            lnkMore.ID = "lnk_More";
            //lnkMore.CssClass = "controlFont";
            lnkMore.ForeColor = System.Drawing.Color.Blue;
            lnkMore.Text = "More";
            //lnkMore.Font.Name = "Arial";
            //lnkMore.Font.Size = 10;
            lnkMore.Attributes.Add("onclick", "javascript:showSave(true);");
            lnkMore.Click += new EventHandler(lnkMore_Click);
            Label count = new Label();
            count.ID = "lbl_count";
            //count.CssClass = "controlFont";
            if (TotalCount != 0)
                count.Text = " Showing record(s) 1 to " + (TotalCount - 1) + " of " + (TotalCount - 1);
            if (TotalCount > GlobalValues.intNoOfRecordsPerPage)
                tc_more.Controls.Add(lnkMore);
            tc_more.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
            tc_more.Controls.Add(count);
            Footer.Cells.Add(tc_more);
            datasheet.Rows.Add(Footer);
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : Load Controls : " + ex.Message);
        }
        finally
        {
            li = null;
        }
    }
    void a_ServerClick(object sender, EventArgs e)
    {
        string[] strdelete = hihDelete.Value.Split('-');
        int delete = Convert.ToInt16(strdelete[0]);
        string af_row_id = strdelete[1];
        SqlCommand sqlobj;
        datasheet.Rows.RemoveAt(delete);
        RowIds = (ArrayList)ViewState["RowIds"];
        RowIds.RemoveAt(delete - 1);
        ViewState["RowIds"] = RowIds;
        //Datasheet V1.0
        ViewState["TotalRecords"] = Convert.ToInt32(ViewState["TotalRecords"].ToString()) - 1;
        ArrayList arrobj = new ArrayList();
        HDDatabase HDD = new HDDatabase();
        string st_delete = "delete from " + object_id + " where af_row_id='" + af_row_id + "'";
        sqlobj = new SqlCommand(st_delete);
        arrobj.Add(sqlobj);
        HDD.ExecuteTransaction(arrobj);
        //Hoodtech 
        DataLoad();
    }

    private void addRow()
    {
        try
        {
            int count = 0;
            if (hihInsertRow.Value != "")
            {
                count = Convert.ToInt16(hihInsertRow.Value) + 1;
            }

            HtmlTableRow tr_assign;
            string strCtrlId = "";
            string strBindRowID = "";
            string strActualCtrlId = "";
            string strCtrlWidth = "";
            string sAttrib_Size = "";
            string sInputFormatMask = "";
            string strDefaultVal = "";
            HDDatabase HDD = new HDDatabase();
            PageInfoLoad PIL = new PageInfoLoad();
            Localization li = new Localization();
            //Page Events
            dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowId);

            DataTable dtaPageSet = dsePageInfo.Tables["PageSet"];
            DataTable dtaPage = dsePageInfo.Tables["Page"];
            DataTable dtaPageKeys = dsePageInfo.Tables["PageKeys"];
            DataTable dtaPageCtrl = dsePageInfo.Tables["PageCtrl"];
            DataSet dsPageEvents = PIL.pageEventHandler(strPageId);
            Hashtable hsControlValues = new Hashtable();
            if (dsPageEvents != null)
            {
                DataSet dsPageInfo = dtaPage.DataSet.Copy(); ;
                if (dsPageEvents.Tables.Count > 0)
                    triggerEvent(dsPageEvents, "PL", ref hsControlValues, ref dsPageInfo, frmObj);
                dsPageInfo.Dispose();
                dsPageInfo = null;
            }
            DataRow[] dr_ctrl = dt_pageCtr.Select("section_name ='__MB_EMPTY_SECTION' AND control_visible=1", "control_seq asc");
            ScreenReader SR = new ScreenReader();
            string af_row_id = SR.getHashKey();
            tr_assign = new HtmlTableRow();
            hihrowids.Value = "";
            tr_assign.ID = "tr_assign_" + af_row_id;
            if (ViewState["RowIds"].ToString() != "")
            {
                RowIds = (ArrayList)ViewState["RowIds"];
                RowIds.Add(af_row_id);
            }
            else
            {
                RowIds.Add(af_row_id);
            }
            ViewState["RowIds"] = RowIds;
            PageCommonFunctions PCF = new PageCommonFunctions();
            for (int i = 0; i < RowIds.Count; i++)
            {
                hihrowids.Value += RowIds[i] + ",";
            }
            hihrowids.Value = hihrowids.Value.TrimEnd(',');
            //Datasheet V2 40
            DataTable dt_count = HDD.GetDataTable("select * from " + object_id + " where " + str_OwnerId.Remove(0, 5) + " or owner_id is null ");
            //if (dt_count != null & dt_count.Rows.Count > 0)
            //{
            //    GetData(af_row_id);
            //}
            if (bDelete != false)
            {
                HtmlTableCell tc_assign = new HtmlTableCell();
                HtmlAnchor a = new HtmlAnchor();
                //Datasheet V1.0
                a.Title = "Delete";
                a.ID = "btn_remove" + af_row_id.ToString();
                a.Attributes.Add("onclick", "javascript:if(confirm('Are you sure you want to delete ?')){Delete('" + tr_assign.ID.ToString() + "');}else{return false;};");
                a.ServerClick += new EventHandler(a_ServerClick);
                a.HRef = "#";
                HtmlImage img = new HtmlImage();
                img.ID = "img" + af_row_id.ToString();
                img.Src = "Images/delete.GIF";
                img.Border = 0;
                a.Controls.Add(img);
                tc_assign.Controls.Add(a);
                tc_assign.Align = "center";
                //tc_assign.Width = "2%";
                //tc_assign.BgColor = "#ffffff";
                tr_assign.Cells.Add(tc_assign);
                tc_assign.Attributes.Add("Class", "datasheet_textbox");
                tc_assign.Attributes.Add("className", "datasheet_textbox");
                HiddenField hfobj = new HiddenField();
                hfobj.ID = "hf_IsNewRow_" + af_row_id;
                hfobj.Value = "true";
                tc_assign.Controls.Add(hfobj);
            }
            count = datasheet.Rows.Count;
            foreach (DataRow dr in dr_ctrl)
            {
                string strAttrib_Type = dr["control_attrib_type"].ToString();
                strActualCtrlId = dr["control_attrib_id"].ToString();
                strCtrlId = dr["control_attrib_id"].ToString();
                string strcontrolHtml = dr["control_html"].ToString();
                strBindRowID = dr["control_bind_id"].ToString();
                strCtrlWidth = dr["control_width"].ToString();
                sAttrib_Size = dr["attrib_size"].ToString();
                if (dr.Table.Columns.Contains("input_mask_format"))
                    sInputFormatMask = dr["input_mask_format"].ToString();
                strDefaultVal = dr["default_value"].ToString();
                bool IsEdit = Convert.ToBoolean(dr["read_only"].ToString());
                if (strDefaultVal.StartsWith("{!") && strDefaultVal.EndsWith("}"))
                {
                    Hashtable hsSysVar = (Hashtable)HttpContext.Current.Session["SysVar"];
                    if (hsSysVar.Contains(strDefaultVal))
                        strDefaultVal = hsSysVar[strDefaultVal].ToString();
                }
                else if (strDefaultVal.StartsWith("{@") && strDefaultVal.EndsWith("}"))
                {
                    security hds = new security();
                    Hashtable hsAppVar = new Hashtable();
                    hds.loadAppVariables(ref hsAppVar);
                    hds = null;
                    if (hsAppVar.Contains(strDefaultVal))
                        strDefaultVal = hsAppVar[strDefaultVal].ToString();
                }
                else if (strDefaultVal == "CurrentDate()")
                {
                    strDefaultVal = DateTime.Now.ToShortDateString();
                }
                if (hsControlValues.Contains("[" + object_name + "].[" + strActualCtrlId + "]"))
                    strDefaultVal = Convert.ToString(hsControlValues["[" + object_name + "].[" + strActualCtrlId + "]"]);

                strCtrlId = strCtrlId + "_" + af_row_id;
                string Object_af_row_id = HDD.GetColumnValue("select af_row_id from sy_obj where object_id='" + object_name + "'");
                DynamicDisplayI DDI = new DynamicDisplayI();
                string sUTC_Offset = DDI.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id");
                string IsPrimary = "";
                switch (strcontrolHtml.ToUpper())
                {
                    case "TB":
                    case "EM":
                        tc_cell = new HtmlTableCell();
                        //tc_cell.BgColor = "#ffffff";
                        tc_cell.NoWrap = true;
                        TextBox txt_obj = new TextBox();
                        //txt_obj.Style.Add("height", "40px");
                        txt_obj.ID = "TB_" + strCtrlId;
                        security sec = new security();
                        bool change_owner = false;

                        HiddenField hf = new HiddenField();
                        if (strBindRowID != "")
                        {
                            hf.ID = "HD_" + strCtrlId;
                            PCF.SetDefaultValueForOwnerID(ref txt_obj, ref hf, strActualCtrlId);
                            tc_cell.Controls.Add(hf);
                        }
                        if (strCtrlWidth != "")
                        {
                            txt_obj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                        }
                        //if (sAttrib_Size != "")
                        //    txt_obj.MaxLength = Convert.ToInt32(sAttrib_Size);
                        tc_cell.Controls.Add(txt_obj);
                        if (strActualCtrlId == "af_row_id")
                        {
                            txt_obj.Text = af_row_id;
                            txt_obj.Visible = false;
                            tc_cell.Visible = false;
                        }
                        //if (bEdit == false)
                        //{
                        //    txt_obj.ReadOnly = true;
                        //    // tc_cell.Disabled = true;
                        //}
                        if (IsEdit == true)
                            txt_obj.ReadOnly = true;
                        txt_obj.CssClass = "datasheet_textbox";
                        IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                        // HiddenField hf1 = new HiddenField();

                        if (strBindRowID != "")
                        {
                            HiddenField hf1 = new HiddenField();
                            hf1.ID = "HD1_" + strCtrlId;
                            //if (strActualCtrlId.ToLower() == "owner_id")
                            //{
                            //    change_owner = sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner");
                            //}
                            //sec = null;
                            if (strActualCtrlId.ToLower() == "owner_id" && !sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner"))
                            {
                                //if (!change_owner)
                                //{
                                    txt_obj.ReadOnly = true;
                                //}
                                //else
                                //{
                                //    if (IsEdit == false & bEdit != false)
                                //        PCF.AddSearchLink(ref tc_cell, strActualCtrlId, hf1.ID, txt_obj.ID, strBindRowID);
                                //    tc_cell.Controls.Add(hf1);
                                //    txt_obj.ReadOnly = true;
                                //    if (IsEdit == false & bEdit != false)
                                //        txt_obj.Attributes.Add("onblur", "javascript:GetData('" + af_row_id + "','" + txt_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                //}
                            }
                            else
                            {
                                tc_cell.Controls.Add(hf1);
                                if (!IsEdit && bCreate)
                                {
                                    PCF.AddSearchLink(ref tc_cell, strActualCtrlId, hf1.ID, txt_obj.ID, strBindRowID);
                                    txt_obj.Attributes.Add("onblur", "javascript:GetData('" + af_row_id + "','" + txt_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                                    txt_obj.Style.Add("vertical-align", "middle");
                                }
                            }
                        }

                        if (sInputFormatMask != "") 
                            PCF.processInputMask(ref tc_cell, txt_obj, sInputFormatMask);

                        if (strAttrib_Type == "DC" || strAttrib_Type == "NU" || strAttrib_Type == "AN" || strAttrib_Type == "FL" || strAttrib_Type == "CU")
                            txt_obj.Style.Add("text-align", "right");
                        if (strAttrib_Type == "DT" & bCreate != false & IsEdit == false)
                        {
                            PageCommonFunctions PC = new PageCommonFunctions();
                            PC.addAjaxCalendarDateTime(txt_obj.ID, ref tc_cell);
                            txt_obj.Text = DDI.getUsersDT(txt_obj.Text, sUTC_Offset);
                        }
                        if (strAttrib_Type == "DA" & bCreate != false & IsEdit == false)
                        {
                            tc_cell.Controls.Add(PCF.addAjaxCalendarDate(txt_obj.ID));
                            if (txt_obj.Text != "")
                            {
                                DateTime da = DateTime.Parse(txt_obj.Text);
                                //txt_obj.Text = da.ToString(li.getDateFormat());
                                txt_obj.Text = da.ToString(MBLocalization.getDateFormat(HttpContext.Current.Session["userlocale"].ToString())); // Added by 'Imran Gani' on 19-Mar-2014, for MBLocale
                            }
                        }
                        if (strcontrolHtml.ToUpper() == "EM" & bCreate != false & IsEdit == false)
                            PCF.provideEmailValidation(ref tc_cell, txt_obj, strActualCtrlId, af_row_id);
                        if (IsPrimary.ToLower() == "true")
                            PCF.addMandatoryValidator(ref tc_cell, txt_obj);
                        //if (strDefaultVal != "")
                        //{
                        //    txt_obj.Text = strDefaultVal;
                        //    hihUpdate.Value = af_row_id + "|" + strActualCtrlId + "|" + strDefaultVal + "|" + strBindRowID + "|" + strcontrolHtml + "|" + IsPrimary;
                        //    GetUpdateData(ref lblMessage);
                        //    hihUpdate.Value = "";
                        //    //txt_obj.Enabled = false;
                        //}
                        //if (bEdit == false)
                        //    txt_obj.ReadOnly = true;
                        if (Isadd == false)
                            txt_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + txt_obj.ID + "','" + (count - 1) + "');");
                        else
                            txt_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + txt_obj.ID + "','" + (count) + "');");
                        HiddenField HD_Cu = new HiddenField();
                        if (strAttrib_Type.ToLower() == "cu")
                        {
                            if (txt_obj.Text != "&nbsp;")
                            {

                                HD_Cu.ID = "HD_Cu_" + strCtrlId + "_" + af_row_id;
                                HD_Cu.Value = txt_obj.Text;
                                txt_obj.Text = DDI.manageCurrency(txt_obj.Text, currencyCode_Rate);
                                tc_cell.Controls.Add(HD_Cu);
                            }

                            txt_obj.Attributes.Add("onfocus", "javascript:GetCurrency('" + HD_Cu.ID.ToString() + "','" + txt_obj.ID.ToString() + "',true);");
                            // txt_obj.Attributes.Add("onblur", "javascript:GetCurrency('" + CurrenyValue + "','" + txt_obj.ID.ToString() + "');");
                        }
                        //Datasheet V2
                        if (strBindRowID == "" & strAttrib_Type.ToLower() != "cu")
                        {
                            if (IsEdit == false & bCreate != false)
                                txt_obj.Attributes.Add("onblur", "javascript:GetData('" + af_row_id + "','" + txt_obj.ID.ToString() + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                        }
                        else if (strBindRowID == "" & strAttrib_Type.ToLower() == "cu")
                            txt_obj.Attributes.Add("onblur", "javascript:GetCurrency('" + HD_Cu.ID.ToString() + "','" + txt_obj.ID.ToString() + "',false);GetData('" + af_row_id + "','" + txt_obj.ID.ToString() + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                        #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                        ////if (tc_cell.Controls.Count <= 1)
                        //if (strBindRowID == "" && IsPrimary.ToLower() != "true")
                        //{
                        //    tc_cell.Width = "140px";
                        //    txt_obj.Width = Unit.Percentage(90);
                        //}
                        //else if (strBindRowID != "" && IsPrimary.ToLower() == "true")
                        //{
                        //    tc_cell.Width = "170";
                        //    txt_obj.Width = Unit.Percentage(75);
                        //}
                        //else
                        //{
                        //    tc_cell.Width = "150";
                        //    txt_obj.Width = Unit.Percentage(80);
                        //}
                        #endregion
                        break;
                    case "PW":
                        tc_cell = new HtmlTableCell();

                        TextBox PW_obj = new TextBox();
                        //tc_cell.BgColor = "#ffffff";
                        tc_cell.NoWrap = true;
                        //PW_obj.Style.Add("height", "40px");
                        PW_obj.ID = "PW_" + strCtrlId;
                        //PW_obj.Width = Unit.Percentage(100);
                        PW_obj.TextMode = TextBoxMode.Password;
                        PW_obj.CssClass = "datasheet_textbox";
                        //if (strDefaultVal != "")
                        //{
                        //    PW_obj.Text = strDefaultVal;
                        //    hihUpdate.Value = af_row_id + "|" + strActualCtrlId + "|" + strDefaultVal + "|" + strBindRowID + "|" + strcontrolHtml + "|" + IsPrimary;
                        //    GetUpdateData(ref lblMessage);
                        //    hihUpdate.Value = "";
                        //    //txt_obj.Enabled = false;
                        //}
                        //if (bEdit == false)
                        //    PW_obj.ReadOnly = true;
                        if (IsEdit)
                            PW_obj.ReadOnly = true;
                        tc_cell.Controls.Add(PW_obj);
                        IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                        if (IsPrimary.ToLower() == "true")
                            PCF.addMandatoryValidator(ref tc_cell, PW_obj);
                        if (IsEdit == false & bCreate != false)
                            PW_obj.Attributes.Add("onblur", "javascript:GetData('" + af_row_id + "','" + PW_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                        if (Isadd == false)
                            PW_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + PW_obj.ID + "','" + (count - 1) + "');");
                        else
                            PW_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + PW_obj.ID + "','" + (count) + "');");
                        #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                        //if (IsPrimary != "true")
                        //{
                        //    tc_cell.Width = "140px";
                        //    PW_obj.Width = Unit.Percentage(90);
                        //}
                        //else
                        //{
                        //    tc_cell.Width = "150";
                        //    PW_obj.Width = Unit.Percentage(90);
                        //}
                        #endregion
                        break;
                    case "ENC": // Added by 'Imran Gani' on 10-Jul-2014, to handle encryption fields.
                        tc_cell = new HtmlTableCell();
                        TextBox ENC_obj = new TextBox();
                        tc_cell.NoWrap = true;
                        ENC_obj.ID = "ENC_" + strCtrlId;
                        //ENC_obj.Width = Unit.Percentage(100);
                        ENC_obj.CssClass = "datasheet_textbox";
                        //if (bEdit == false)
                        //    ENC_obj.ReadOnly = true;
                        if (IsEdit)
                            ENC_obj.ReadOnly = true;
                        tc_cell.Controls.Add(ENC_obj);
                        IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                        if (IsPrimary.ToLower() == "true")
                            PCF.addMandatoryValidator(ref tc_cell, ENC_obj);
                        if (IsEdit == false & bCreate != false)
                            ENC_obj.Attributes.Add("onblur", "javascript:GetData('" + af_row_id + "','" + ENC_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                        if (Isadd == false)
                            ENC_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + ENC_obj.ID + "','" + (count - 1) + "');");
                        else
                            ENC_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + ENC_obj.ID + "','" + (count) + "');");
                        #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                        //if (IsPrimary != "true")
                        //{
                        //    tc_cell.Width = "140px";
                        //    ENC_obj.Width = Unit.Percentage(90);
                        //}
                        //else
                        //{
                        //    tc_cell.Width = "150";
                        //    ENC_obj.Width = Unit.Percentage(90);
                        //}
                        #endregion
                        break;
                    case "AN":
                        tc_cell = new HtmlTableCell();
                        TextBox AN_obj = new TextBox();
                        //tc_cell.BgColor = "#ffffff";
                        tc_cell.NoWrap = true;
                        //AN_obj.Style.Add("height", "40px");
                        AN_obj.ID = "AN_" + strCtrlId;
                        //AN_obj.Width = Unit.Percentage(100);
                        if (strCtrlWidth != "")
                            AN_obj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                        if (sAttrib_Size != "")
                            AN_obj.MaxLength = Convert.ToInt32(sAttrib_Size);
                        HDD = new HDDatabase();
                        string Obj_id = HDD.GetColumnValue("select object_id from sy_pg where page_id='" + strPageId + "'");
                        string Autonumber = PCF.getAutoNumberValue(Obj_id, strActualCtrlId, 0);
                        //if (bEdit == false)
                        //    AN_obj.ReadOnly = true;
                        if (Autonumber != "")
                        {
                            AN_obj.Text = Autonumber;
                            //DataSheetV3
                            //hihUpdate.Value = af_row_id + "|" + strActualCtrlId + "|" + Autonumber + "|" + strBindRowID + "|" + strcontrolHtml + "|" + IsPrimary;
                            //GetUpdateData(ref lblMessage);
                            //hihUpdate.Value = "";
                            AN_obj.ReadOnly = true;
                        }
                        //if (strDefaultVal != "")
                        //{
                        //    AN_obj.Text = strDefaultVal;
                        //    hihUpdate.Value = af_row_id + "|" + strActualCtrlId + "|" + strDefaultVal + "|" + strBindRowID + "|" + strcontrolHtml + "|" + IsPrimary;
                        //    GetUpdateData(ref lblMessage);
                        //    hihUpdate.Value = "";
                        //    //txt_obj.Enabled = false;
                        //}
                        if (Autonumber != "")
                            AN_obj.Text = Autonumber;
                        AN_obj.CssClass = "datasheet_textbox";
                        tc_cell.Controls.Add(AN_obj);
                        IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                        if (IsPrimary.ToLower() == "true")
                            PCF.addMandatoryValidator(ref tc_cell, AN_obj);
                        if (IsEdit == false & bCreate != false)
                            AN_obj.Attributes.Add("onblur", "javascript:GetData('" + af_row_id + "','" + AN_obj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                        if (Isadd == false)
                            AN_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + AN_obj.ID + "','" + (count - 1) + "');");
                        else
                            AN_obj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + AN_obj.ID + "','" + (count) + "');");
                        #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                        //if (IsPrimary != "true")
                        //{
                        //    tc_cell.Width = "140px";
                        //    AN_obj.Width = Unit.Percentage(90);
                        //}
                        //else
                        //{
                        //    tc_cell.Width = "150";
                        //    AN_obj.Width = Unit.Percentage(90);
                        //}
                        #endregion
                        break;
                    case "CB":
                        tc_cell = new HtmlTableCell();
                        //tc_cell.Attributes.Add("class", "Dynamic_HtmlTableCell");
                        CheckBox CB = new CheckBox();
                        //if (bEdit == false)
                        //    CB.Enabled = false;
                        if (IsEdit == true)
                            CB.Enabled = false;
                        //tc_cell.BgColor = "#ffffff";
                        tc_cell.NoWrap = true;
                        CB.ID = "CB_" + strCtrlId;
                        tc_cell.Controls.Add(CB);
                        tc_cell.Align = "center";
                        if (IsEdit == false & bCreate != false)
                            CB.Attributes.Add("onclick", "javascript:GetData('" + af_row_id + "','" + CB.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','false');");
                        if (Isadd == false)
                            CB.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + CB.ID + "','" + (count - 1) + "');");
                        else
                            CB.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + CB.ID + "','" + (count) + "');");
                        break;
                    case "TA":
                        tc_cell = new HtmlTableCell();
                        tc_cell.NoWrap = true;
                        TextBox txtobj = new TextBox();
                        txtobj.TextMode = TextBoxMode.MultiLine;
                        //txtobj.Rows = 4;
                        //txtobj.Width = Unit.Percentage(100);
                        txtobj.ID = "TA_" + strCtrlId;
                        txtobj.Wrap = true;
                        //if (bEdit == false)
                        //    txtobj.ReadOnly = true;
                        //tc_cell.BgColor = "#ffffff";
                        if (IsEdit == true)
                            txtobj.ReadOnly = true;
                        //if (strDefaultVal != "")
                        //{
                        //    txtobj.Text = strDefaultVal;
                        //    hihUpdate.Value = af_row_id + "|" + strActualCtrlId + "|" + strDefaultVal + "|" + strBindRowID + "|" + strcontrolHtml + "|" + IsPrimary;
                        //    GetUpdateData(ref lblMessage);
                        //    hihUpdate.Value = "";
                        //    //txt_obj.Enabled = false;
                        //}
                        //if (sAttrib_Size != "")
                        //    txtobj.MaxLength = Convert.ToInt32(sAttrib_Size);
                        txtobj.CssClass = "datasheet_textbox";
                        tc_cell.Controls.Add(txtobj);
                        IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                        if (IsPrimary.ToLower() == "true")
                            PCF.addMandatoryValidator(ref tc_cell, txtobj);
                        if (IsEdit == false & bCreate != false)
                            txtobj.Attributes.Add("onblur", "javascript:GetData('" + af_row_id + "','" + txtobj.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                        if (Isadd == false)
                            txtobj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + txtobj.ID + "','" + (count - 1) + "');");
                        else
                            txtobj.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + txtobj.ID + "','" + (count) + "');");
                        #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                        //if (IsPrimary != "true")
                        //{
                        //    tc_cell.Width = "200px";
                        //    txtobj.Width = Unit.Percentage(95);
                        //}
                        //else
                        //{
                        //    tc_cell.Width = "210";
                        //    txtobj.Width = Unit.Percentage(90);
                        //}
                        #endregion
                        break;
                    case "DD":
                        tc_cell = new HtmlTableCell();
                        //tc_cell.BgColor = "#ffffff";
                        tc_cell.NoWrap = true;
                        DropDownList DDL = new DropDownList();
                        BindControl BC = new BindControl();
                        DataTable dt = new DataTable();
                        DDL.ID = "DD_" + strCtrlId;
                        //DDL.Width = Unit.Percentage(100);
                        //if (bEdit == false)
                        //    DDL.Enabled = false;
                        if (IsEdit == true)
                            DDL.Enabled = false;
                        if (strBindRowID != "")
                        {
                            string sql = "";
                            sql = BC.GetBindSql(strBindRowID);
                            if (sql.Trim() != "")
                                dt = HDD.GetDataTable(sql);
                            DDL.DataSource = dt;
                            DDL.DataTextField = "Fld";
                            DDL.DataValueField = "Val";
                            DDL.DataBind();
                        }
                        DDL.CssClass = "datasheet_dropdown";
                        tc_cell.Controls.Add(DDL);
                        IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                        if (IsPrimary.ToLower() == "true")
                            PCF.addMandatoryValidator(ref tc_cell, DDL);
                        if (IsEdit == false & bCreate != false)
                            DDL.Attributes.Add("onchange", "javascript:GetData('" + af_row_id + "','" + DDL.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                        if (Isadd == false)
                            DDL.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + DDL.ID + "','" + (count - 1) + "');");
                        else
                            DDL.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + DDL.ID + "','" + (count) + "');");
                        #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                        //if (strBindRowID == "" && IsPrimary.ToLower() != "true")
                        //{
                        //    tc_cell.Width = "140px";
                        //    DDL.Width = Unit.Percentage(90);
                        //}
                        //else if (strBindRowID != "" && IsPrimary.ToLower() == "true")
                        //{
                        //    tc_cell.Width = "170";
                        //    DDL.Width = Unit.Percentage(75);
                        //}
                        //else
                        //{
                        //    tc_cell.Width = "150";
                        //    DDL.Width = Unit.Percentage(80);
                        //}
                        #endregion
                        break;
                    case "DL": // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                        tc_cell = new HtmlTableCell();
                        tc_cell.NoWrap = true;
                        DropDownList DDL_Droplist = new DropDownList();
                        DDL_Droplist.ID = "DPL_" + strCtrlId;
                        //if (bEdit == false)
                        //    DDL_Droplist.Enabled = false;
                        if (IsEdit == true)
                            DDL_Droplist.Enabled = false;
                        HDDatabase hd = new HDDatabase();
                        DataTable dt_Droplist = hd.GetDataTable("select * from [sy_pg_ctr_droplist] where [page_id] = '" + dr["page_id"].ToString() + "' and [control_id] = '" + dr["af_row_id"].ToString() + "';");
                        foreach (DataRow dr_temp in dt_Droplist.Select("droplist_value in ('none','empty')"))
                            dr_temp["droplist_value"] = "";
                        DDL_Droplist.DataSource = dt_Droplist;
                        DDL_Droplist.DataTextField = "droplist_value";
                        DDL_Droplist.DataValueField = "droplist_value";
                        DDL_Droplist.DataBind();
                        #region New code Added by 'Imran Gani' on 19-Mar-2014, to use switch case with MBLocale
                        //foreach (DataRow dr in dt_Droplist.Rows) // Added by 'Imran Gani' on 19-Mar-2014, for MBLocale
                        //{
                        //    string sDLText = dr["droplist_value"].ToString();
                        //    try
                        //    {
                        //        switch (droTemp["control_attrib_type"].ToString().ToLower())
                        //        {
                        //            case "dt":
                        //            case "da":
                        //                sDLText = MBLocalization.getLocalizedDate(HttpContext.Current.Session["userlocale"].ToString(), DateTime.Parse(dr["droplist_value"].ToString()));
                        //                break;
                        //            case "nu":
                        //            case "an":
                        //                sDLText = MBLocalization.getLocalizedInteger(HttpContext.Current.Session["userlocale"].ToString(), int.Parse(dr["droplist_value"].ToString()));
                        //                break;
                        //            case "cu":
                        //            case "dc":
                        //            case "fl":
                        //                sDLText = MBLocalization.getLocalizedDecimal(HttpContext.Current.Session["userlocale"].ToString(), double.Parse(dr["droplist_value"].ToString()));
                        //                break;
                        //        }
                        //    }
                        //    catch (Exception ex)
                        //    {
                        //        sDLText = dr["droplist_value"].ToString();
                        //        dr["droplist_value"] = new Localization().getDBValueFromLocale(dr["droplist_value"].ToString(), droTemp["control_attrib_type"].ToString());
                        //    }
                        //    DDL_Droplist.Items.Add(new ListItem(sDLText, dr["droplist_value"].ToString()));
                        //}
                        #endregion
                        if (HttpContext.Current.Request.QueryString["PK"] == null)
                            if (strDefaultVal != "")
                                DDL_Droplist.Items.FindByText(strDefaultVal).Selected = true;

                        DDL_Droplist.CssClass = "datasheet_dropdown";
                        tc_cell.Controls.Add(DDL_Droplist);
                        IsPrimary = HDD.GetColumnValue("select is_primary  from sy_obj_att where object_id='" + Object_af_row_id + "' and attrib_id='" + strActualCtrlId + "'");
                        if (IsPrimary.ToLower() == "true")
                            PCF.addMandatoryValidator(ref tc_cell, DDL_Droplist);
                        if (IsEdit == false & bCreate != false)
                            DDL_Droplist.Attributes.Add("onchange", "javascript:GetData('" + af_row_id + "','" + DDL_Droplist.ID + "','" + strActualCtrlId + "','" + strBindRowID + "','" + strcontrolHtml.ToUpper() + "','" + IsPrimary + "');");
                        if (Isadd == false)
                            DDL_Droplist.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + DDL_Droplist.ID + "','" + (count - 1) + "');");
                        else
                            DDL_Droplist.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) Navigate('" + DDL_Droplist.ID + "','" + (count) + "');");
                        #region commented by 'Imran Gani' on 19-Sep-2014, for avoiding width property
                        //if (strBindRowID == "" && IsPrimary.ToLower() != "true")
                        //{
                        //    tc_cell.Width = "140px";
                        //    DDL.Width = Unit.Percentage(90);
                        //}
                        //else if (strBindRowID != "" && IsPrimary.ToLower() == "true")
                        //{
                        //    tc_cell.Width = "170";
                        //    DDL.Width = Unit.Percentage(75);
                        //}
                        //else
                        //{
                        //    tc_cell.Width = "150";
                        //    DDL.Width = Unit.Percentage(80);
                        //}
                        #endregion
                        break;
                }
                tr_assign.Cells.Add(tc_cell);
            }
            int intRow = (datasheet.Rows.Count + 1) % 2;
            //tr_assign.VAlign = "middle";
            tr_assign.Attributes.Add("Class", "Grid_Row" + intRow.ToString());
            tr_assign.Attributes.Add("onMouseOver", "this.className='Grid_Scroll_BG'");
            tr_assign.Attributes.Add("onMouseOut", "this.className='" + "Grid_Row" + intRow.ToString() + "'");
            tr_assign.Height = "21px"; // sirvatsan
            //if (Isadd == false)
            //{
            //    datasheet.Rows.Insert(count - 1, tr_assign);
            //}
            //else
            //    datasheet.Rows.Insert(count, tr_assign);
            datasheet.Rows.Insert(1, tr_assign);
            
            // commented by jayashree on 19-sep-2014 for handling related Info
           //security HDS = new security();
           //GenerateGrid objGG = new GenerateGrid();
           //if (HDS.allRightsForNGMODEL() == false)
           //{
           //     if (Isadd == false)
           //     {
           //         objGG.showadditionalsections(strPagesetRowId, ref frmObj, dsePageInfo);
           //     }
           // }
            //Datasheet V1.0
            if (tr_assign.Cells[1].Controls[0].ID.Contains("HD"))
            {
                if (tr_assign.Cells[1].Controls[1] != null)
                    tr_assign.Cells[1].Controls[1].Focus();
            }
            else
                tr_assign.Cells[1].Controls[0].Focus();
            //Datasheet V1.0
            int Tot = Convert.ToInt32(ViewState["TotalRecords"].ToString()) + 1;
            Control Con = datasheet.FindControl("lbl_count");
            if (Con != null)
            {
                Label lbl = (Label)Con;
                if (datasheet.Rows.Count > GlobalValues.intNoOfRecordsPerPage)
                    lbl.Text = " Showing record(s) 1 to " + (datasheet.Rows.Count - 2) + " of " + Tot;
                else
                    lbl.Text = " Showing record(s) 1 to " + (datasheet.Rows.Count - 2) + " of " + Tot;

            }
            ViewState["TotalRecords"] = Tot;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : Add new row : " + ex.Message);
        }
        finally
        {

        }
    }

    private ArrayList GetUpdateData(ref Label lblMessage)
    {
        //string test = strBindId;
        string strBindRowID = "";
        ArrayList update = new ArrayList();
        ArrayList arrobj = new ArrayList();
        string af_row_id = "";
        string control_id = "";
        string value = "";
        string ControlHtml = "";
        string Isprimary = "";
        HDDatabase HDD = new HDDatabase();
        PageInfoLoad PIL = new PageInfoLoad();
        Localization ll = new Localization();
        DynamicDisplayI ddi = new DynamicDisplayI();
        SqlCommand sqlobj;
        string table = HDD.GetColumnValue("select page_table_name  from sy_pg where af_row_id ='" + page_id + "'");

        DataSet dsPageEvents = PIL.pageEventHandler(strPageId);
        Hashtable hsControlValues = new Hashtable();
        try
        {
            if (hihUpdate.Value != "")
            {
                string strupdate = hihUpdate.Value;
                string[] strvalues = strupdate.Split('|');
                af_row_id = strvalues[0];
                control_id = strvalues[1];
                value = strvalues[2];
                strBindRowID = strvalues[3];
                ControlHtml = strvalues[4];
                Isprimary = strvalues[5];
                string CheckId = HDD.GetColumnValue("select af_row_id from " + object_id + " where  af_row_id='" + af_row_id + "'");
                if (CheckId == "")
                {
                    GetData(af_row_id);
                }
                //Datasheet V2 27
                string CtrType = HDD.GetColumnValue("select control_attrib_type  from sy_pg_ctr where page_id='" + page_id + "' and control_id='" + control_id + "'");
                if (CtrType == "DA")
                    value = MBLocalization.getDateValue(HttpContext.Current.Session["userlocale"].ToString(), value);
                if (CtrType == "DT")
                    value = ll.getDateTime4TimeZone(value, ddi.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id"), true, false);
                ll = null;
                ddi = null;
                if (dsPageEvents != null)
                {
                    dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowId);
                    DataTable dtaPageSet = dsePageInfo.Tables["PageSet"];
                    DataTable dtaPage = dsePageInfo.Tables["Page"];
                    DataTable dtaPageKeys = dsePageInfo.Tables["PageKeys"];
                    DataTable dtaPageCtrl = dsePageInfo.Tables["PageCtrl"];
                    DataSet dsPageInfo = dtaPage.DataSet.Copy();
                    if (dsPageEvents.Tables.Count > 0)
                    {
                        if (dsPageEvents.Tables[0].Rows.Count != 0)
                        {
                            foreach (DataTable dt in dsPageEvents.Tables)
                            {
                                DataRow[] drEvents = null;
                                if (dt.Columns.Contains("event_sequence"))
                                    drEvents = dt.Select("", "event_sequence asc");
                                else
                                    drEvents = dt.Select();

                                foreach (DataRow dr in drEvents)
                                {
                                    string sEventCode = dr["page_event"].ToString();
                                    switch (sEventCode)
                                    {
                                        case "PS":
                                            triggerEvent(dsPageEvents, sEventCode, ref hsControlValues, ref dsPageInfo, null);
                                            value = ApplyEventValue(sEventCode, hsControlValues, control_id, value);
                                            break;
                                        case "PU":
                                            triggerEvent(dsPageEvents, sEventCode, ref hsControlValues, ref dsPageInfo, null);
                                            string old_value = HDD.GetColumnValue("select " + control_id + " from " + object_id + " where af_row_id='" + af_row_id + "'");
                                            if (old_value != "")
                                                value = ApplyEventValue(sEventCode, hsControlValues, control_id, value);
                                            break;
                                        case "PAS":
                                            triggerEvent(dsPageEvents, sEventCode, ref hsControlValues, ref dsPageInfo, null);
                                            value = ApplyEventValue(sEventCode, hsControlValues, control_id, value);
                                            break;
                                        case "PAU":
                                            triggerEvent(dsPageEvents, sEventCode, ref hsControlValues, ref dsPageInfo, null);
                                            value = ApplyEventValue(sEventCode, hsControlValues, control_id, value);
                                            break;
                                        case "PL":
                                            triggerEvent(dsPageEvents, sEventCode, ref hsControlValues, ref dsPageInfo, null);
                                            value = ApplyEventValue(sEventCode, hsControlValues, control_id, value);
                                            
                                            break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (strBindRowID != null & strBindRowID != "Nobind" & ControlHtml == "TB")
                {
                    // string strbindtext = "";
                    BindControl BC = new BindControl();
                    string sql1 = BC.GetBindSql(strBindRowID, false);
                    DataSet ds = new DataSet();
                    ds = HDD.GetDataset(sql1);
                    if (ds != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                if (value != "")
                                {
                                    DataRow[] drr = ds.Tables[0].Select("fld='" + value + "'");
                                    if (drr.Length > 0)
                                    {
                                        value = drr[0]["val"].ToString();
                                    }
                                    else
                                    {
                                        value = "";
                                        Response.Write(ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;Invalid Data", true));
                                        Response.End();
                                    }
                                }
                            }
                        }
                    }

                }
                bool status = true;
                if (ControlHtml == "PW" || ControlHtml == "ENC")//Added by jayashree on 19-september-2014,for handling password and encryption controltype
                {
                    value = security.encrypt(value);
                }
                if (value == "" )
                {
                    value = null;
                }
                else 
                {
                    value = Server.HtmlEncode(value).Replace("'", "''").Trim() ;
                }
                string st_upadate = "Update " + table + " Set [" + control_id + "]=";
                if (value == null)
                    st_upadate += "NULL where af_row_id='" + af_row_id + "'";
                else
                    st_upadate += "'" + value + "' where af_row_id='" + af_row_id + "'";
                //,modified_at='" + DateTime.Now.ToUniversalTime().ToString() + "' where af_row_id='" + af_row_id + "'";
                if (Isprimary.ToLower() == "true" & value != null)
                {
                    string val = HDD.GetColumnValue("Select " + control_id + " From " + table + " where " + control_id + "='" + value + "' and af_row_id not in ('" + af_row_id + "');");
                    if (val == "")
                    {
                        sqlobj = new SqlCommand(st_upadate);
                        arrobj.Add(sqlobj);
                         status = HDD.ExecuteTransaction(arrobj);
                        Response.Write("");
                    }
                    else
                    {
                        hihUpdate.Value = "";
                        Response.Write(ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;Duplicate Values cannot be inserted.", true));
                      //  Response.End();

                    }
                }
                else if (Isprimary.ToLower() == "false")
                {
                    sqlobj = new SqlCommand(st_upadate);
                    arrobj.Add(sqlobj);
                    status = HDD.ExecuteTransaction(arrobj);
                    Response.Write("");

                }
                if (Isprimary.ToLower() == "true" & value == null)
                {
                    hihUpdate.Value = "";
                    Response.Write(ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;Please Insert a value in mandatory fields.", true));
                    Response.End();
                }

                    if (status == false)
                    {
                        hihUpdate.Value = "";
                        Response.Write(ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;Data Insert not successful." + HDD.ErrorMessage, true));
                        Response.End();
                        ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "alert('" + HDD.ErrorMessage + "')", true);
                    }
                    else
                    {
                        hihUpdate.Value = "";
                        if (Isaddnew == false && Isadd == false)
                        {
                            //Response.Write("null");
                            Response.End();
                        }
                        lblMessage.Text = "";
                    }
                //}
                //else
                //{
                //    if (Isaddnew == false)
                //    {
                //        Response.Write("null");
                //        Response.End();
                //    }
                //}
            }

        }
        catch (Exception ex)
        {
            lblMessage.Text = ErrMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + ex.Message, true);
        }
        finally
        {
            //HDD = null;

        }
        return arrobj;
    }

    public bool triggerEvent(DataSet dsPageEvents, string sPageEvent, ref Hashtable hsAssignControls, ref DataSet PageInfo, HtmlForm frmObj)
    {
        bool bReturn = true;
        HDDatabase HDD = new HDDatabase();
        Master objMaster = new Master();
        PageInfoLoad PIL = new PageInfoLoad();
        try
        {
            string sFunctionName = "";
            foreach (DataTable dt in dsPageEvents.Tables)
            {
                DataRow[] drEvents = null;
                if (dt.Columns.Contains("event_sequence"))
                    drEvents = dt.Select("", "event_sequence asc");
                else
                    drEvents = dt.Select();

                foreach (DataRow dr in drEvents)
                    if (dr["page_event"].ToString().ToLower() == sPageEvent.ToLower())
                    {
                        if (sPageEvent.ToLower() == "pl")
                            if (frmObj != null)

                                // Added by Srivatsan for testing
                                if (HttpContext.Current.Request.Url.AbsoluteUri.ToLower().Contains("transdoc.aspx"))
                                {

                                }
                                //else
                                //{
                                //    if (frmObj.Page.IsPostBack && !checkForReadOnlyControl(ref PageInfo, dr["event_ass_cont"].ToString())) continue;
                                //}

                        string sPageId = dt.TableName;//HDD.GetColumnValue("select page_id from sy_pg where af_row_id='" + dt.Rows[0]["af_row_id"].ToString() + "'");
                        object oReturn = null;
                        string sParam = "";
                        if (dr["event_type"].ToString() == "av")
                        {
                            sParam = dr["event_function"].ToString();
                            string tempsParam = dr["event_function"].ToString();
                            if (sParam.StartsWith("{!") && sParam.EndsWith("}"))
                            {
                                tempsParam = tempsParam.Remove(tempsParam.Length - 1, 1);
                                tempsParam = tempsParam.Remove(0, 2);
                                string sSysValue = HDD.GetColumnValue("Select sy_var_value from sy_var where sy_var_name = '" + tempsParam + "'");

                                if (sSysValue.Contains("["))
                                {
                                    string sObject_id = sSysValue.Substring(sSysValue.IndexOf("[") + 1, sSysValue.IndexOf(".", sSysValue.IndexOf("[") + 1) - (sSysValue.IndexOf("[") + 1));
                                    string sSql = "Select object_table from sy_obj where object_id='" + sObject_id + "'";
                                    string sObject_table = HDD.GetColumnValue(sSql);
                                    sSql = "select page_id from sy_pg where object_id='" + sObject_id + "'";
                                    string sPage_id = HDD.GetColumnValue(sSql);
                                    sSql = "Select multiple_recs_page from sy_pg where page_id = '" + sPage_id + "'";
                                    string stemp = HDD.GetColumnValue(sSql);
                                    bool is_multi_rec_page = Convert.ToBoolean(stemp == "" ? "false" : stemp);
                                    int iStartPos = sSysValue.IndexOf("[") + 1;
                                    iStartPos = sSysValue.IndexOf(".", iStartPos) + 1;
                                    int iEndPos = sSysValue.Length - 1;
                                    iEndPos = sSysValue.IndexOf("]", iStartPos);
                                    //string sField = sSysValue.Substring(sSysValue.IndexOf(".") + 1, sSysValue.Length - 1 - (sSysValue.IndexOf(".") + 1));
                                    string sField = sSysValue.Substring(iStartPos, iEndPos - iStartPos);
                                    tempsParam = sObject_table + "." + sField;

                                    if (is_multi_rec_page)
                                    {
                                        string sCtrlId = dr["event_ass_cont"].ToString();
                                        for (int i = 0; i < PageInfo.Tables[sPage_id].Rows.Count; i++)
                                        {
                                            string svalue = HDD.GetColumnValue(sSysValue.Replace("[" + sObject_id + "." + sField + "]", PageInfo.Tables[sPage_id].Rows[i][sField].ToString()));
                                            hsAssignControls.Add(sCtrlId + "_" + i.ToString(), svalue);
                                        }
                                    }
                                    else
                                    {
                                        string sCtrlId = dr["event_ass_cont"].ToString();
                                        string svalue = HDD.GetColumnValue(sSysValue.Replace("[" + sObject_id + "." + sField + "]", PageInfo.Tables[sPage_id].Rows[0][sField].ToString()));
                                        hsAssignControls.Add(sCtrlId, svalue);
                                        oReturn = svalue;
                                        //if (GlobalValues.hsSysVar.Contains(sParam))
                                        //{
                                        //    oReturn = GlobalValues.hsSysVar[sParam];
                                        //}
                                    }
                                }
                                else
                                {
                                    Hashtable hsSysVar = (Hashtable)HttpContext.Current.Session["SysVar"];
                                    if (hsSysVar.Contains(sParam))
                                    {
                                        oReturn = hsSysVar[sParam];
                                    }
                                    /*if (GlobalValues.hsSysVar.Contains(sParam))
                                    {
                                        oReturn = GlobalValues.hsSysVar[sParam];
                                    }*/
                                }
                            }
                            else if (sParam.StartsWith("{@") && sParam.EndsWith("}"))
                            {
                                //sParam = sParam.Remove(sParam.Length - 1, 1);
                                //sParam = sParam.Remove(0, 2);
                                security hds = new security();
                                Hashtable hsAppVar = new Hashtable();
                                hds.loadAppVariables(ref hsAppVar);
                                hds = null;
                                if (hsAppVar.Contains(sParam))
                                {
                                    oReturn = hsAppVar[sParam];
                                }
                                //if (GlobalValues.hsAppVar.Contains(sParam))
                                //{
                                //    oReturn = GlobalValues.hsAppVar[sParam];
                                //}
                            }
                            else if (sParam.StartsWith("[") && sParam.EndsWith("]"))
                            {
                                string sObject_id = sParam.Substring(sParam.IndexOf("[") + 1, sParam.IndexOf(".") - (sParam.IndexOf("[") + 1));
                                string sSql = "Select object_table from sy_obj where object_id='" + sObject_id + "'";
                                string sObject_table = HDD.GetColumnValue(sSql);
                                sSql = "Select multiple_recs_page from sy_pg where page_id = 'p_" + sObject_id + "'";
                                string stemp = HDD.GetColumnValue(sSql);
                                bool is_multi_rec_page = Convert.ToBoolean(stemp == "" ? "false" : stemp);
                                string sField = sParam.Substring(sParam.IndexOf(".") + 1, sParam.Length - 1 - (sParam.IndexOf(".") + 1));
                                sParam = sObject_table + "." + sField;

                                if (is_multi_rec_page)
                                {
                                    string sCtrlId = dr["event_ass_cont"].ToString();
                                    for (int i = 0; i < PageInfo.Tables["p_" + sObject_id].Rows.Count; i++)
                                    {
                                        //GlobalValues.hsSysVar.Add(sParam + "_" + i.ToString(), PageInfo.Tables["p_" + sObject_id].Rows[i][sField].ToString());
                                        hsAssignControls.Add(sCtrlId + "_" + i.ToString(), PageInfo.Tables["p_" + sObject_id].Rows[i][sField].ToString());
                                    }
                                }
                                else
                                {
                                    Hashtable hsSysVar = (Hashtable)HttpContext.Current.Session["SysVar"];
                                    if (hsSysVar.Contains(sParam))
                                        oReturn = hsSysVar[sParam].ToString();
                                    else
                                        oReturn = "";
                                    /*if (GlobalValues.hsSysVar.Contains(sParam))
                                        oReturn = GlobalValues.hsSysVar[sParam].ToString();
                                    else
                                        oReturn = "";*/
                                }
                            }
                        }
                        else
                        {
                            oReturn = PIL.invokeEvent(dr["event_function"].ToString(), PageInfo.Tables[sPageId], ref sFunctionName, dr["event_type"].ToString(), ref hsAssignControls, dr);
                        }
                        if (dr["event_type"].ToString() == "a")
                        {
                            string sCtrlId = dr["event_ass_cont"].ToString();
                            if (!hsAssignControls.Contains(sCtrlId))
                                hsAssignControls.Add(sCtrlId, oReturn);
                            else
                                hsAssignControls[sCtrlId] = oReturn;
                        }
                        else if (dr["event_type"].ToString() == "av")
                        {
                            string sCtrlId = dr["event_ass_cont"].ToString();
                            if (!hsAssignControls.Contains(sCtrlId))
                                hsAssignControls.Add(sCtrlId, oReturn);
                            else
                                hsAssignControls[sCtrlId] = oReturn;
                        }
                        else if (dr["event_type"].ToString() == "v")
                        {
                            if (oReturn != null)
                            {
                                bReturn = Convert.ToBoolean(oReturn);
                                if (bReturn == false)
                                {
                                    if (oReturn.ToString() != "")
                                    {
                                        sFunctionName = sFunctionName + " returned " + oReturn.ToString();
                                        if (objMaster.DeleteMessage == "")
                                            objMaster.DeleteMessage = sFunctionName;
                                    }
                                    return bReturn;
                                }
                            }
                        }
                    }
            }
        }

        catch (Exception ex)
        {
            LogWriter.WriteLog("triggerEvent : Error : " + ex.Message);
            objMaster.DeleteMessage = ex.Message;
            bReturn = false;
        }
        return bReturn;
    }

    private string ErrMessage(string msg, bool isError)
    {
        return "<div class=\"" + (isError == true ? "mbErrorMessage" : "mbMessage") + "\">" + msg + "</div>";
    }
    public string ErrorMessage
    {
        get
        {
            return this.strErrMessage;
        }
    }

    private string ApplyEventValue(String EventCode, Hashtable hsvalue, string Control_id, string Value)
    {
        if (hsvalue.Count > 0)
        {
            for (int i = 0; i < hsvalue.Count; i++)
            {
                if (hsvalue.Contains("[" + object_name + "].[" + Control_id + "]"))
                    Value = Convert.ToString(hsvalue["[" + object_name + "].[" + Control_id + "]"]);
            }

        }
        return Value;
    }

    private bool GetData(string id)
    {
        ScreenReader SR = new ScreenReader();
        Master MA = new Master();
        PageInfoLoad PIL = new PageInfoLoad();
        bool blnStatus = true;
        HDDatabase HDD = new HDDatabase();
        DynamicDisplayI DDI = new DynamicDisplayI();
        DataSet dseInputInfo = new DataSet();
        dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowId);
        DataTable dtaPageSet = dsePageInfo.Tables["PageSet"];
        DataTable dtaPage = dsePageInfo.Tables["Page"];
        DataTable dtaPageKeys = dsePageInfo.Tables["PageKeys"];
        DataTable dtaPageCtrl = dsePageInfo.Tables["PageCtrl"];
        if (dseTempInputInfo.Tables.Contains(dtaPage.Rows[0]["page_id"].ToString()) == false)
            SR.CreatePageDataTable(dseTempInputInfo, dtaPage, dtaPageCtrl);
        dseTempInputInfo.Tables[strPageId].Clear();
        droPageData = dseTempInputInfo.Tables[strPageId].NewRow();
        string ctrl = "TB" + "_" + "af_row_id" + "_" + id;
        string value = id;
        droPageData["af_row_id"] = value;
        dseTempInputInfo.Tables[strPageId].Rows.Add(droPageData);

        dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowId);
        dseInputInfo.Merge(dseTempInputInfo, true);
        ArrayList arrobj = new ArrayList();
        SqlCommand cmdObj = new SqlCommand();
        SqlParameter spmObj = new SqlParameter();
        string strInsert = "insert into " + object_id + "(af_row_id,created_by,created_at,modified_at,modified_by,owner_id) values (@af_row_id,@created_by,@created_at,@modified_at,@modified_by,@owner_id)";
        cmdObj.Parameters.Add("af_row_id", SqlDbType.NVarChar).Value = value;
        cmdObj.Parameters.Add("created_by", SqlDbType.NVarChar).Value = HttpContext.Current.Session["user_afrowid"].ToString();
        cmdObj.Parameters.Add("created_at", SqlDbType.DateTime).Value = DateTime.Now.ToUniversalTime().ToString();
        cmdObj.Parameters.Add("modified_at", SqlDbType.DateTime).Value = DateTime.Now.ToUniversalTime().ToString();
        cmdObj.Parameters.Add("modified_by", SqlDbType.NVarChar).Value = HttpContext.Current.Session["user_afrowid"].ToString();
        cmdObj.Parameters.Add("owner_id", SqlDbType.NVarChar).Value = HttpContext.Current.Session["user_afrowid"].ToString();
        cmdObj.CommandText = strInsert;
        arrobj.Add(cmdObj);
        HDD.ExecuteTransaction(arrobj);
        return blnStatus;
    }
    private void GetPageViewType()
    {
        HDDatabase HDD = new HDDatabase();
        try
        {
            //string strsql = "select af_row_id from sy_pgs where pageset_id = '" + strPagesetRowId + "'";
            //string strpagesetid = HDD.GetColumnValue(strsql);
            string strsql1 = "select mem_seq as mem_seq ,mem_id as ListType , mem_name as ListView from sy_acr_mem where acr_id = '67f864457589b041' and mem_seq = 1 union select sam.mem_seq as mem_seq , spm.mode as ListType , sam.mem_name as ListView from sy_pgs_mode spm inner join sy_acr_mem sam on spm.mode = sam.mem_id where spm.pageset_id = '" + strPagesetRowId + "'";
            DataTable dt = HDD.GetDataTable(strsql1);
            if (dt.Rows.Count > 1)
            {
                ddlPageViewType.DataSource = dt.DefaultView;
                ddlPageViewType.DataTextField = "ListView";
                ddlPageViewType.DataValueField = "ListType";
                ddlPageViewType.DataBind();
                //ddlPageViewType.Items.Insert(0, new ListItem("--Select--", ""));
            }
        }
        catch (Exception e1)
        {
            LogWriter.WriteLog("Error in GetPageViewType");
        }
        finally
        {
            HDD = null;
        }

    }
    private void getpageicons()
    {
        PageIcons icons = new PageIcons();
        try
        {
            lblHeader.Text = icons.geticontextfrompageset(Request.QueryString["pgs_id"], 1).ToString() + "&nbsp;" + lblHeader.Text;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error :getpageicons()" + ex.Message);
            lblHeader.Text = "&nbsp;<img src=" + PageIcons.strdefaulticon.ToString() + "></img>&nbsp;";
        }
        finally
        {
            icons = null;
        }
    }
    private Literal GetPageIcons(string strPagesetRowID)
    {
        Literal iconlit = new Literal();
        PageIcons icons = new PageIcons();
        try
        {

            string iconpath = icons.geticonsfrompageset(strPagesetRowID.Replace("'", "''"), 2);
            icons = null;

            iconlit.Text = "&nbsp;<img src = " + iconpath + " style='vertical-align:middle;'></img>&nbsp;";
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error GetPageIcons:" + ex.Message);
            iconlit.Text = "&nbsp;<img src = " + PageIcons.strdefaulticon.ToString() + "></img>&nbsp; ";
        }
        finally
        {
            icons = null;
        }
        return iconlit;
    }
    protected void ddlPageViewType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPageViewType.SelectedValue != null)
        {
            Response.Redirect("DisplayGrid.aspx?pgs_id=" + strPagesetRowId + "&mn=" + strMenuRowId + "&ViewType=" + ddlPageViewType.SelectedValue);

        }

    }
    protected void btnAddNewTop_ServerClick(object sender, EventArgs e)
    {
        Isaddnew = true;
        DataLoad();
        addRow();
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {

        //search = "";
    }
    protected void a_search_ServerClick(object sender, EventArgs e)
    {
        PageInfoLoad PIL = new PageInfoLoad();
        HDDatabase HDD = new HDDatabase();
        GenerateGrid GG = new GenerateGrid();
        dsePageInfo = PIL.GetPageSetPagesSrchInfo(strPagesetRowId);

        DataTable dtaPageSet = dsePageInfo.Tables["PageSet"];
        DataTable dtaPage = dsePageInfo.Tables["Page"];
        DataTable dtaPageKeys = dsePageInfo.Tables["PageKeys"];
        DataTable dtaPageCtrl = dsePageInfo.Tables["Page Controls"];
        DataTable dtaPageSrch = dsePageInfo.Tables["PageSrch"];
        search = GG.PagesetObjectSearchSql(ref dtaPageSrch, ref dtaPageCtrl, ref dtaPage, frmObj, ref HDD);
        search = search.Replace(strPageId, "");
        //Datasheet V1.0
        search = search.Replace("[].", string.Empty);
        IsScrh = true;
        IsViewAll = false;
        DataLoad();
    }

    protected void a_lnk_ServerClick(object sender, EventArgs e)
    {

    }
    protected void lnkBtnViewAll_Click(object sender, EventArgs e)
    {

    }

    private string InsertNewRecord()
    {
        HDDatabase HDD = new HDDatabase();
        PageInfoLoad PIL = new PageInfoLoad();
        ScreenReader SR = new ScreenReader();
        Localization loc = new Localization();
        DataSet dsePageData = new DataSet();
        string strCtrlId = "";
        string strCtrlValue = "";
        DataRow droPageData;
        string sRet = "", sNew_Af_row_id;
        try
        {
            if (Request.QueryString["pgs_id"] == null || Request.QueryString["pgs_id"].ToString() == "") return sRet;
            if (Request.QueryString["NewRowID"] == null || Request.QueryString["NewRowID"].ToString() == "")
                sNew_Af_row_id = SR.getHashKey();
            else
                sNew_Af_row_id = Request.QueryString["NewRowID"].ToString();
            strPagesetRowId = Request.QueryString["pgs_id"].ToString();
            dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowId);
            DataTable dtaPageSet = dsePageInfo.Tables["PageSet"];
            DataTable dtaPage = dsePageInfo.Tables["Page"];
            DataTable dtaPageKeys = dsePageInfo.Tables["PageKeys"];
            DataTable dtaPageCtrl = dsePageInfo.Tables["PageCtrl"];
            SR.CreatePageDataTable(dsePageData, dtaPage, dtaPageCtrl);
            string strPageId = dtaPage.Rows[0]["page_id"].ToString();
            droPageData = dsePageData.Tables[strPageId].NewRow();
            foreach (DataRow droPageCtrl in dtaPageCtrl.Rows)
            {
                strCtrlId = droPageCtrl["control_attrib_id"].ToString();
                string strCtrlType = droPageCtrl["control_html"].ToString();
                string strCtrlColumn = droPageCtrl["control_attrib_id"].ToString();
                string strBindRowID = droPageCtrl["control_bind_id"].ToString();
                string strDefaultValue = droPageCtrl["default_value"].ToString();
                switch (strCtrlType.ToUpper())
                {
                    case "DA":
                    case "DT":
                    case "TB":
                    case "EM":
                        if (Request.QueryString["TB_" + strCtrlId + "_" + sNew_Af_row_id] == null)
                            break;
                        else
                            strCtrlValue = Request.QueryString["TB_" + strCtrlId + "_" + sNew_Af_row_id].ToString().Trim();

                        if (strCtrlValue == "" && strDefaultValue != "")
                            strCtrlValue = strDefaultValue;
                        else if (strCtrlValue == "")
                            break;

                        if (strBindRowID != "")
                        {
                            BindControl BC = new BindControl();
                            DataSet dsBind = new DataSet();
                            string data = strCtrlValue;

                            string sql = BC.GetBindSql(strBindRowID);
                            dsBind = HDD.GetDataset(sql);
                            if (dsBind != null)
                            {
                                if (dsBind.Tables.Count > 0)
                                {
                                    if (dsBind.Tables[0].Rows.Count > 0)
                                    {
                                        BC.HandleLocalizedBindText(dsBind.Tables[0], droPageCtrl["control_bind_id"].ToString());
                                        DataRow[] drrbind = null;
                                        try
                                        {
                                            drrbind = dsBind.Tables[0].Select("fld = '" + data.Replace("'", "''") + "'");
                                        }
                                        catch
                                        {
                                            return sRet = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                        }
                                        if (drrbind != null)
                                        {
                                            if (drrbind.Length > 0)
                                                strCtrlValue = drrbind[0]["val"].ToString();
                                        }
                                        else
                                            return sRet = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                    }
                                    else
                                        return sRet = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                }
                            }
                            if (droPageCtrl["control_attrib_id"].ToString() == GlobalValues.ModifiedDate)
                                strCtrlValue = DateTime.Now.ToUniversalTime().ToString();

                            strCtrlValue = loc.getDBValueFromLocale(strCtrlValue.Trim(), droPageCtrl["control_attrib_type"].ToString());
                        }
                        else
                        {

                            string masterattrib_id = "";
                            DataRow[] drrmasterlinkfield = null;
                            if (dtaPageKeys.Rows.Count > 0)
                            {
                                drrmasterlinkfield = dtaPageKeys.Select("attrib_id = '" + strCtrlId + "'");
                                if (drrmasterlinkfield.Length > 0)
                                    masterattrib_id = drrmasterlinkfield[0]["attrib_id"].ToString().ToLower();
                            }

                            if (strCtrlId.ToLower() == masterattrib_id.ToLower())
                            {
                                string strTableName = "";
                                string bindfield = "";
                                string sMSFieldDataType = "";
                                if (dtaPageKeys != null)
                                {
                                    if (dtaPageKeys.Rows.Count > 0)
                                    {
                                        string masterobj = dtaPageKeys.Rows[0]["master_obj"].ToString();
                                        bindfield = dtaPageKeys.Rows[0]["display_att"].ToString();
                                        strTableName = HDD.GetColumnValue("sy_obj", "object_table", "object_id='" + masterobj + "'");
                                        sMSFieldDataType = HDD.GetColumnValue("select attrib_data_type from sy_obj_att where object_id = (select af_row_id from sy_obj where object_id = '" + masterobj + "') and attrib_id = '" + bindfield + "';");
                                    }
                                }
                                if (strTableName != "")
                                {
                                    strCtrlValue = loc.getDBValueFromLocale(strCtrlValue.Trim(), sMSFieldDataType);

                                    MasterDetail MD = new MasterDetail();
                                    DataTable dtaMaster = MD.GetMasterDataFromValue(strTableName, strCtrlValue, bindfield);

                                    if (dtaMaster != null)
                                    {
                                        if (dtaMaster.Rows.Count > 0)
                                            strCtrlValue = dtaMaster.Rows[0]["af_row_id"].ToString();
                                        else
                                            return sRet = "Invalid data for " + droPageCtrl["control_name"].ToString() + " :" + strCtrlValue;
                                    }
                                }
                            }
                            else
                            {
                                if (droPageCtrl["control_attrib_id"].ToString() == GlobalValues.ModifiedDate)
                                    strCtrlValue = DateTime.Now.ToUniversalTime().ToString();
                                strCtrlValue = loc.getDBValueFromLocale(strCtrlValue.Trim(), droPageCtrl["control_attrib_type"].ToString());
                            }
                        }
                        break;
                    case "AN":
                        if (Request.QueryString["AN_" + strCtrlId + "_" + sNew_Af_row_id] == null || Request.QueryString["AN_" + strCtrlId + "_" + sNew_Af_row_id].ToString().Trim() == "")
                            break;
                        else
                            strCtrlValue = Request.QueryString["AN_" + strCtrlId + "_" + sNew_Af_row_id].ToString();
                        break;
                    case "PW":
                        if (Request.QueryString["PW_" + strCtrlId + "_" + sNew_Af_row_id] == null)
                            break;
                        else
                            strCtrlValue = Request.QueryString["PW_" + strCtrlId + "_" + sNew_Af_row_id].ToString().Trim();

                        if (strCtrlValue == "" && strDefaultValue != "")
                            strCtrlValue = strDefaultValue;
                        else if (strCtrlValue == "")
                            break;

                        if (droPageCtrl["control_attrib_id"].ToString() == GlobalValues.ModifiedDate)
                            strCtrlValue = DateTime.Now.ToUniversalTime().ToString();
                        strCtrlValue = security.encrypt(strCtrlValue);
                        break;
                    case "ENC": // Added by 'Imran Gani' on 10-Jul-2014, to handle encryption fields.
                        if (Request.QueryString["ENC_" + strCtrlId + "_" + sNew_Af_row_id] == null)
                            break;
                        else
                            strCtrlValue = Request.QueryString["ENC_" + strCtrlId + "_" + sNew_Af_row_id].ToString().Trim();

                        if (strCtrlValue == "" && strDefaultValue != "")
                            strCtrlValue = strDefaultValue;
                        else if (strCtrlValue == "")
                            break;

                        if (droPageCtrl["control_attrib_id"].ToString() == GlobalValues.ModifiedDate)
                            strCtrlValue = DateTime.Now.ToUniversalTime().ToString();
                        strCtrlValue = security.encrypt(strCtrlValue);
                        break;
                    case "TA":
                        if (Request.QueryString["TA_" + strCtrlId + "_" + sNew_Af_row_id] == null)
                            break;
                        else
                            strCtrlValue = Request.QueryString["TA_" + strCtrlId + "_" + sNew_Af_row_id].ToString().Trim();

                        if (strCtrlValue == "" && strDefaultValue != "")
                            strCtrlValue = strDefaultValue;
                        else if (strCtrlValue == "")
                            break;

                        if (droPageCtrl["control_attrib_id"].ToString() == GlobalValues.ModifiedDate)
                            strCtrlValue = DateTime.Now.ToString();
                        break;
                    case "CB":
                        if (Request.QueryString["CB_" + strCtrlId + "_" + sNew_Af_row_id] == null)
                            break;
                        else
                            strCtrlValue = Request.QueryString["CB_" + strCtrlId + "_" + sNew_Af_row_id].ToString().Trim();
                        if (strCtrlValue == "" && strDefaultValue != "")
                            strCtrlValue = strDefaultValue;
                        else if (strCtrlValue == "")
                            strCtrlValue = "False";
                        break;
                    case "DD":
                    case "DDE":
                        if (Request.QueryString["DD_" + strCtrlId + "_" + sNew_Af_row_id] == null)
                            break;
                        else
                            strCtrlValue = Request.QueryString["DD_" + strCtrlId + "_" + sNew_Af_row_id].ToString().Trim();

                        if (strCtrlValue == "" && strDefaultValue != "")
                            strCtrlValue = strDefaultValue;
                        else if (strCtrlValue == "")
                            break;

                        if (strCtrlType.ToUpper() == "DDE") // Added by srivatsan for DDE change 
                        {
                            if (strBindRowID != "")
                            {
                                BindControl BC = new BindControl();
                                string sql = BC.GetBindSql(strBindRowID);
                                if (sql.Trim() != "")
                                {
                                    DataTable dt = HDD.GetDataTable(sql);
                                    if (dt != null)
                                    {
                                        DataRow[] drrdata = null;
                                        try
                                        {
                                            drrdata = dt.Select("val = '" + strCtrlValue + "'");
                                        }
                                        catch
                                        {
                                            drrdata = dt.Select("fld = '" + strCtrlValue + "'");
                                        }
                                        if (drrdata != null)
                                        {
                                            if (drrdata.Length > 0)
                                                strCtrlValue = drrdata[0]["val"].ToString();
                                            else
                                                return sRet = "Invalid data for " + droPageCtrl["control_name"].ToString();
                                        }
                                    }
                                }
                                BC = null;
                            }
                        }
                        break;
                    //case "DL": // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                    //    Control dlcon = DDI.FindControl(frmObj.Controls, strCtrlId);
                    //    if (dlcon != null)
                    //    {
                    //        if (dlcon is HiddenField)
                    //        {
                    //            HiddenField hfmaster = (HiddenField)DDI.FindControl(frmObj.Controls, strCtrlId);
                    //            strRet = hfmaster.Value;
                    //        }
                    //        else
                    //        {
                    //            DropDownList ddlObj = (DropDownList)DDI.FindControl(frmObj.Controls, strCtrlId);
                    //            strRet = ddlObj == null ? "" : ddlObj.SelectedValue;
                    //        }
                    //    }
                    //    break;
                }
                droPageData[strCtrlId] = strCtrlValue;
            }
            droPageData["af_row_id"] = sNew_Af_row_id;
            dsePageData.Tables[strPageId].Rows.Add(droPageData);
            Master MA = new Master();
            if (MA.ProcessOperation(dsePageInfo, dsePageData, "INSERT"))
                sRet = "success";
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error: DataSheet: InsertNewRecord:" + ex.Message);
        }
        finally
        {
        }
        return sRet;
    }
}
